comp.lang.ada
 help / color / mirror / Atom feed
From: "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de>
Subject: Re: understanding floating point types
Date: Sun, 22 Aug 2010 11:51:14 +0200
Date: 2010-08-22T11:51:12+02:00	[thread overview]
Message-ID: <mt3els2pgx78$.1dwj1p44vk16d.dlg@40tude.net> (raw)
In-Reply-To: 74406fc1-f64b-4a3e-9dd6-301f1ed467ab@w30g2000yqw.googlegroups.com

On Sun, 22 Aug 2010 02:11:59 -0700 (PDT), Ada novice wrote:

>     I'm trying to understand the floating point representation in the
> binary and decimal bases. If D is the number of decimal digits in the
> mantissa, then the number if bits B is given by B = D(1og 10/1og 2) +
> 1 = 3.32 * D + 1 and this rounded up to the next integer value.
> 
> Thus for a float type in Ada, mantissa D = 6, then B = 3.32(6) +1 = 21
> to the nearest upwards integer value. GNAT GPL 2010 shows that
> Float'Mantissa is 21 bits.
>
> Now the TOTAL number of bits in a float (Float'Size in GNAT GPL) is B
> = 32 giving the range of exponent as -4B to 4B i.e. -128 to 128. And
> this gives in decimal base a exponent (in Float'Last) of log(2^128)/
> (log 10) = 38.53, which is 38 in GNAT GPL.

Float'Machine_Mantissa = 24 =
23 explicit bits + 1 hidden bit (considering IEEE 754 single precision)

Float'Mantissa gives the model binary mantissa, the least number of bits
required to represent specified decimal mantissa (the "number B"). It is a
model attribute, a view of the real machine's number of bits, which is 24.
[*]

Compare:

   type My_Float is digits 1;

My_Float'Machine_Mantissa = 24 (32-bit IEEE 754 is used to model it)
My_Float'Mantissa = 5 (= 4+1)

   type My_Float is digits 2;

My_Float'Machine_Mantissa = 24 (32-bit IEEE 754 is used to model it)
My_Float'Mantissa = 8 (= 7+1)

etc

-----------
* Excluding denormalized numbers

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de



  reply	other threads:[~2010-08-22  9:51 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-08-22  9:11 understanding floating point types Ada novice
2010-08-22  9:51 ` Dmitry A. Kazakov [this message]
2010-08-22 10:37   ` Ada novice
2010-08-22 10:39     ` Ada novice
2010-08-22 13:57     ` Dmitry A. Kazakov
2010-08-22 17:15       ` Ada novice
2010-08-22 18:16         ` Dmitry A. Kazakov
2010-08-22 19:05           ` Ada novice
2010-08-22 19:34             ` Dmitry A. Kazakov
2010-08-23  6:29               ` Ada novice
2010-08-23  6:40                 ` J-P. Rosen
2010-08-23  7:13                 ` Dmitry A. Kazakov
2010-08-23  7:15             ` Martin
2010-08-23 11:42               ` Ada novice
2010-08-24 12:14                 ` Ada novice
2010-08-24 14:05                   ` Jacob Sparre Andersen
2010-08-24 14:36                     ` Ada novice
2010-08-22 17:22       ` Yannick Duchêne (Hibou57)
2010-08-22 18:49         ` Ada novice
replies disabled

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