comp.lang.ada
 help / color / mirror / Atom feed
* understanding floating point types
@ 2010-08-22  9:11 Ada novice
  2010-08-22  9:51 ` Dmitry A. Kazakov
  0 siblings, 1 reply; 19+ messages in thread
From: Ada novice @ 2010-08-22  9:11 UTC (permalink / raw)


Hi,
    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.

Now if I take the total number of bits for a float i.e. 32 and
subtract the number of bits for the mantissa (21), I get 11.

If I set 11 = 3.32(decimal equivalent) + 1, I get the unknown "decimal
equivalent" as 3 digits.

If I understand correctly, then 2 out of the 3 digits are for the
exponent. And what about the remaining 1 digit? Is it for a sign
before the mantissa or before the exponent?

I guess that I'm confusing between decimal and binary representations.
Some help would be highly appreciated :).

Thanks.

YC




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

end of thread, other threads:[~2010-08-24 14:36 UTC | newest]

Thread overview: 19+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-08-22  9:11 understanding floating point types Ada novice
2010-08-22  9:51 ` Dmitry A. Kazakov
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

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