From: "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de>
Subject: Re: understanding floating point types
Date: Sun, 22 Aug 2010 20:16:15 +0200
Date: 2010-08-22T20:16:13+02:00 [thread overview]
Message-ID: <toekjoyml5tx$.4xvgjm3annj4$.dlg@40tude.net> (raw)
In-Reply-To: 37d8fbc1-fdaf-4ca9-9393-6163f2e3fa2e@s9g2000yqd.googlegroups.com
On Sun, 22 Aug 2010 10:15:24 -0700 (PDT), Ada novice wrote:
> I didn't quite get this part. In my previous example with say a = 2.33
> and b = 3.45. Does Multiplication of a with b mean converting each of
> a and b in model number first and then do the multiplication and
> afterwards approximating the result to the nearest model number? Or
> the multiplication will just be performed with the two numbers as 2.33
> X 3.45 = 8.0385 and then approximating this result to the nearest
> model number?
No, the result is 8.0385 (assuming 32-bit machine numbers). Try this:
with Ada.Text_IO; use Ada.Text_IO;
procedure Test_Float is
type My_Float is digits 3;
X : My_Float := 2.33;
Y : My_Float := 3.45;
begin
Put_Line ("Model view:" & My_Float'Image (X*Y));
Put_Line ("The reality:" & Float'Image (Float (X*Y)));
end Test_Float;
It should print:
Model view: 8.04E+00
The reality: 8.03850E+00
When you print the number using My_Float'Image that rounds the machine
number to the nearest model number. In computations and conversions
machine numbers are left untouched.
--
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de
next prev parent reply other threads:[~2010-08-22 18:16 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
2010-08-22 17:15 ` Ada novice
2010-08-22 18:16 ` Dmitry A. Kazakov [this message]
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