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 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,6cf602b7ea8a1df1 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2001-02-15 07:30:57 PST From: "M. Kotiaho" Newsgroups: comp.lang.ada Subject: Re: Floating point accuracy Date: Thu, 15 Feb 2001 09:22:11 -0600 Organization: LMMFC - D Message-ID: <3A8BF422.69723366@m_a_i_l.com> References: <3a8bbb84$1@pull.gecm.com> NNTP-Posting-Host: 138.209.253.101 Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Mailer: Mozilla 4.7 [en] (WinNT; U) X-Accept-Language: en Path: supernews.google.com!sn-xit-02!supernews.com!news.tele.dk!216.218.192.242!news.he.net!pacifier!coop.net!newsfeed1.global.lmco.com!svlnews.lmms.lmco.com!not-for-mail Xref: supernews.google.com comp.lang.ada:5276 Date: 2001-02-15T09:22:11-06:00 List-Id: Martin Dowie wrote: > I'm trying to mimic 64-bit unsigned integers (that will represent > nanoseconds) on a > PowerPC (Green Hills target compiler for the PowerPC doesn't support 64 bit > unsigned directly - unless you know differently!). > > I'm doing this by having a most sigificant and least significant 32bit > unsigned in what will > eventually be a private record and providing my own operators. However my > routine to > convert from microseconds to nanoseconds is puzzling me. I had always > thought that a > float declared a 'digits 15' would give me 15 significant digits of > accuracy - I'm sure I'm > only using up to 13 in these test, yet the last two results return the same > values. > > clearly, I'm missing something... Yes ... look more closely at your results ... the values you print for "ns" differ in one digit (last non-zero digit). The values for "ls" are also different (the last value has ...66..., the previous one has ...65...). It is only for "ms" and "MS" that the values are the same. You should not expect otherwise, since you are losing information when you take the 'floor operation in computing Float_MS. It has nothing to do with the number of significant digits (since you have enough). Here is the math: 'Last - 1: Float_MS = Floor( (2**32 - 2)*1000 / 2**32 ) = Floor( 1000 - 2000/2**32 ) = 999 'Last: Float_MS = Floor( (2**32 - 1)*1000 / 2**32 ) = Floor( 1000 - 1000/2**32 ) = 999 ...... > > test 'Last - 1 > ns = 4.29496729400000E+12 > ms = 9.99000000000000E+02 > MS = 4.29067232870400E+12 > ls = 4.29496529600000E+09 > > ms => 999 ls => 4294965296 > test 'Last > ns = 4.29496729500000E+12 > ms = 9.99000000000000E+02 > MS = 4.29067232870400E+12 > ls = 4.29496629600000E+09 > > ms => 999 ls => 4294966296 Regards, Markku Kotiaho