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=-1.9 required=5.0 tests=BAYES_00,FREEMAIL_FROM autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,548c38bb2d3e1bb6,start X-Google-NewGroupId: yes X-Google-Attributes: gida07f3367d7,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!postnews.google.com!w30g2000yqw.googlegroups.com!not-for-mail From: Ada novice Newsgroups: comp.lang.ada Subject: understanding floating point types Date: Sun, 22 Aug 2010 02:11:59 -0700 (PDT) Organization: http://groups.google.com Message-ID: <74406fc1-f64b-4a3e-9dd6-301f1ed467ab@w30g2000yqw.googlegroups.com> NNTP-Posting-Host: 193.11.22.91 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 X-Trace: posting.google.com 1282468319 1501 127.0.0.1 (22 Aug 2010 09:11:59 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Sun, 22 Aug 2010 09:11:59 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: w30g2000yqw.googlegroups.com; posting-host=193.11.22.91; posting-account=Rr9I-QoAAACS-nOzpA-mGxtAlZ46Nb6I User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2.8) Gecko/20100722 Firefox/3.6.8 (.NET CLR 3.5.30729),gzip(gfe) Xref: g2news1.google.com comp.lang.ada:13595 Date: 2010-08-22T02:11:59-07:00 List-Id: 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