comp.lang.ada
 help / color / mirror / Atom feed
From: Ludovic Brenta <ludovic@ludovic-brenta.org>
Subject: Re: Looking For Simple Routine To Put Integer Into Float
Date: Tue, 25 May 2010 00:53:41 +0200
Date: 2010-05-25T00:53:41+02:00	[thread overview]
Message-ID: <87eih0ap3e.fsf@ludovic-brenta.org> (raw)
In-Reply-To: 570f8963-82ba-42b9-981f-0f92e59161b3@a2g2000prd.googlegroups.com

ChristopherL <clusardi2k@aol.com> writes:

> Can you modify the below code to convert an integer variable of 32
> bits to a variable of type float.

Why does it matter that the integer variable is 32 bits?

How many bits does the float type use?

> type Unknown_integer_type is range -(2**16) ..(2**16) -1; -- 32 Bit
> Integer

This looks like a 17-bit integer type to me, not 32-bit.

> An_Unknown_Integer: Unknown_integer_type;
> An_Integer: Integer;
> A_Float: Float;            -- Hoping this float is usually 32 bits

Then it cannot hold a 32-bit integer without losing some precision,
since some of the float's 32 bits will be reserved for the exponent.
But since the integer type is only 17-bit wide, that's OK; the mantissa
of a 32-bit float is very probably wider than 17 bits.

> An_Integer := 1234;
>
> An_Unknown_Integer := An_Integer;
>
> A_Float := Float (An_Unknown_Integer);

That's a type conversion, it assigns the value 1234.0 to A_Float.  Since
you ask a question, I can only assume that that's now what you wanted.
So what is it that you want, exactly?

-- 
Ludovic Brenta.



       reply	other threads:[~2010-05-24 22:53 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <570f8963-82ba-42b9-981f-0f92e59161b3@a2g2000prd.googlegroups.com>
2010-05-24 22:53 ` Ludovic Brenta [this message]
2010-05-24 23:05 ` Looking For Simple Routine To Put Integer Into Float Jeffrey R. Carter
2010-05-25  2:47 ` Stephen Leake
2010-05-25 16:34   ` mockturtle
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox