comp.lang.ada
 help / color / mirror / Atom feed
* Re: Looking For Simple Routine To Put Integer Into Float
       [not found] <570f8963-82ba-42b9-981f-0f92e59161b3@a2g2000prd.googlegroups.com>
@ 2010-05-24 22:53 ` Ludovic Brenta
  2010-05-24 23:05 ` Jeffrey R. Carter
  2010-05-25  2:47 ` Stephen Leake
  2 siblings, 0 replies; 4+ messages in thread
From: Ludovic Brenta @ 2010-05-24 22:53 UTC (permalink / raw)


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.



^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Looking For Simple Routine To Put Integer Into Float
       [not found] <570f8963-82ba-42b9-981f-0f92e59161b3@a2g2000prd.googlegroups.com>
  2010-05-24 22:53 ` Looking For Simple Routine To Put Integer Into Float Ludovic Brenta
@ 2010-05-24 23:05 ` Jeffrey R. Carter
  2010-05-25  2:47 ` Stephen Leake
  2 siblings, 0 replies; 4+ messages in thread
From: Jeffrey R. Carter @ 2010-05-24 23:05 UTC (permalink / raw)


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

If you want an unconstrained, 32-bit, signed integer type, something from 
Interfaces (such as Integer_32) is usually the way to go.

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

Why hope? If you need a 32-bit floating-point type, again something from 
Interfaces might be in order, or declare an appropriate type for your application:

type Real is digits 6 [range Low .. High];
for Real'Size use 32;

In any case, the size of Float should be documented for your compiler.

> An_Integer := 1234;
> 
> An_Unknown_Integer := An_Integer;

This shouldn't compile, as An_Integer has a different type than 
An_Unknown_Integer; you need a type conversion.

> A_Float := Float (An_Unknown_Integer);

What is the point of Unknown_Integer_Type and An_Unknown_Integer? What's wrong with

A_Float := Float (An_Integer);

?

-- 
Jeff Carter
"You can never forget too much about C++."
115



^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Looking For Simple Routine To Put Integer Into Float
       [not found] <570f8963-82ba-42b9-981f-0f92e59161b3@a2g2000prd.googlegroups.com>
  2010-05-24 22:53 ` Looking For Simple Routine To Put Integer Into Float Ludovic Brenta
  2010-05-24 23:05 ` Jeffrey R. Carter
@ 2010-05-25  2:47 ` Stephen Leake
  2010-05-25 16:34   ` mockturtle
  2 siblings, 1 reply; 4+ messages in thread
From: Stephen Leake @ 2010-05-25  2:47 UTC (permalink / raw)


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.
>
> 
>
> A_Float := Float (An_Unknown_Integer);

This answers your question as asked; it converts any integer type to the
Float type.

Perhaps you want to ask something else?

-- 
-- Stephe



^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Looking For Simple Routine To Put Integer Into Float
  2010-05-25  2:47 ` Stephen Leake
@ 2010-05-25 16:34   ` mockturtle
  0 siblings, 0 replies; 4+ messages in thread
From: mockturtle @ 2010-05-25 16:34 UTC (permalink / raw)


On May 25, 4:47 am, Stephen Leake <stephen_le...@stephe-leake.org>
wrote:
> ChristopherL <clusard...@aol.com> writes:
> > Can you modify the below code to convert an integer variable of 32
> > bits to a variable of type float.
>
> > A_Float := Float (An_Unknown_Integer);
>
> This answers your question as asked; it converts any integer type to the
> Float type.
>
> Perhaps you want to ask something else?

My theory: maybe the OP wanted to do a "bitwise copy" of the 4 octets
of the Integer into the 4 octets of the Float? Something like an
Unchecked_Conversion?  (This would explain the "Hoping this float is
usually 32 bits" remark)
>
> --
> -- Stephe




^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2010-05-25 16:34 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <570f8963-82ba-42b9-981f-0f92e59161b3@a2g2000prd.googlegroups.com>
2010-05-24 22:53 ` Looking For Simple Routine To Put Integer Into Float Ludovic Brenta
2010-05-24 23:05 ` Jeffrey R. Carter
2010-05-25  2:47 ` Stephen Leake
2010-05-25 16:34   ` mockturtle

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