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 15:57:42 +0200
Date: 2010-08-22T15:57:40+02:00	[thread overview]
Message-ID: <ghi6wajpwx2t.1u5g5erb7i1i6$.dlg@40tude.net> (raw)
In-Reply-To: 7b0ca24f-4a5e-43a9-9f71-e4adffb98694@q1g2000yqg.googlegroups.com

On Sun, 22 Aug 2010 03:37:35 -0700 (PDT), Ada novice wrote:

> On Aug 22, 11:51�am, "Dmitry A. Kazakov" <mail...@dmitry-kazakov.de>
> wrote:
>> 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)
> 
> Thanks. The Float'Machine_Mantissa remains constant in your examples
> with 1 and 2 precision digits. Is the Float'Machine_Mantissa a
> predefined value that is constant for any precision digit requested?

No, it is the is best fitting machine number available (compiler's choice):

 � type My_Float is digits 7;

   My_Float'Machine_Mantissa = 53 (64-bit IEEE 754 is used to model it)
   My_Float'Mantissa = 25

> I have a second query: Say we consider the type My_Float is digits 2.
> This means that between the model numbers, the resolution is 1/(2^8)
> with the 8 in the expression obtained as 4 X 2. Am I right? Now if we
> have to multiply two numbers: say a = 2.33 and b = 3.45. Does Ada
> first convert each operation to its nearest model number and then do
> the multiplication and represent the result to its nearest model
> number? Or does Ada do the multiplication first and then represent the
> result to to its nearest model number?

I would expect that all computations performed in machine numbers, not
because it is mandated, I believe it is not, but because it is simpler to
implement. At least with GNAT it is so. Try this:

   type My_Float is digits 2;
   X : My_Float := 1.0 / 3.0;
   ...
   Put_Line (Float'Image (Float (X)));

The output will be: 3.33333E-01

If you can pick any number from the interval [0.33, 0.34[ to represent 1/3
in with 2 decimal digits. Why not 0.333333?

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



  parent reply	other threads:[~2010-08-22 13:57 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
2010-08-22 10:37   ` Ada novice
2010-08-22 10:39     ` Ada novice
2010-08-22 13:57     ` Dmitry A. Kazakov [this message]
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