From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-0.3 required=5.0 tests=BAYES_00, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: 103376,548c38bb2d3e1bb6 X-Google-NewGroupId: yes X-Google-Attributes: gida07f3367d7,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII Path: g2news1.google.com!news4.google.com!proxad.net!feeder1-2.proxad.net!194.25.134.126.MISMATCH!newsfeed01.sul.t-online.de!t-online.de!newsfeed.arcor.de!newsspool3.arcor-online.net!news.arcor.de.POSTED!not-for-mail From: "Dmitry A. Kazakov" Subject: Re: understanding floating point types Newsgroups: comp.lang.ada User-Agent: 40tude_Dialog/2.0.15.1 MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 8bit Reply-To: mailbox@dmitry-kazakov.de Organization: cbb software GmbH References: <74406fc1-f64b-4a3e-9dd6-301f1ed467ab@w30g2000yqw.googlegroups.com> <7b0ca24f-4a5e-43a9-9f71-e4adffb98694@q1g2000yqg.googlegroups.com> Date: Sun, 22 Aug 2010 15:57:42 +0200 Message-ID: NNTP-Posting-Date: 22 Aug 2010 15:57:40 CEST NNTP-Posting-Host: 38a07c4d.newsspool4.arcor-online.net X-Trace: DXC=G1JPO4m^1C0lIh70@[ On Sun, 22 Aug 2010 03:37:35 -0700 (PDT), Ada novice wrote: > On Aug 22, 11:51�am, "Dmitry A. Kazakov" > 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