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-7-bit Path: g2news1.google.com!news3.google.com!feeder.news-service.com!nf02.dk.telia.net!starscream.dk.telia.net!news.tele.dk!news.tele.dk!small.news.tele.dk!bnewspeer01.bru.ops.eu.uu.net!bnewspeer00.bru.ops.eu.uu.net!emea.uu.net!newsfeed.arcor.de!newsspool1.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="us-ascii" Content-Transfer-Encoding: 7bit Reply-To: mailbox@dmitry-kazakov.de Organization: cbb software GmbH References: <74406fc1-f64b-4a3e-9dd6-301f1ed467ab@w30g2000yqw.googlegroups.com> Date: Sun, 22 Aug 2010 11:51:14 +0200 Message-ID: NNTP-Posting-Date: 22 Aug 2010 11:51:12 CEST NNTP-Posting-Host: c495e545.newsspool3.arcor-online.net X-Trace: DXC=`XL=92DLDJ1^8FBo0_81f>McF=Q^Z^V384Fo<]lROoR18kF[ 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