From mboxrd@z Thu Jan 1 00:00:00 1970 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: fee84,dbd5e8a2d19cc3f9 X-Google-Attributes: gidfee84,public From: "Morten Skaarup Jensen" Subject: Re: Inaccurate logarithm in Pascal Date: 1999/03/24 Message-ID: <7dad0r$cha$1@news.net.uni-c.dk>#1/1 X-Deja-AN: 458324619 References: <7d81qg$soq$1@news.net.uni-c.dk> <36ffa646.349337953@usenet.pa.dec.com> X-MimeOLE: Produced By Microsoft MimeOLE V4.72.3110.3 X-Complaints-To: usenet@news.net.uni-c.dk X-Trace: news.net.uni-c.dk 922269531 12842 130.225.78.145 (24 Mar 1999 09:58:51 GMT) Organization: UNI-C NNTP-Posting-Date: 24 Mar 1999 09:58:51 GMT Newsgroups: comp.unix.osf.osf1 Steve Lionel wrote in message <36ffa646.349337953@usenet.pa.dec.com>... >On Tue, 23 Mar 1999 13:37:30 +0100, "Morten Skaarup Jensen" > wrote: > >> >>DEC Pascal gives the option of either a fast or an accurate math library. >>According to the manual "accurate" is default, but the results of the "ln" >>function are only accurate to about 9 significant figures which is not >>enough for me. >> >>Is there a bug in the "ln" function or am I linking to the "fast" math >>library? Any help will be appreciated. > >Do you have a specific example? 9 significant digits is more than I'd >expect with single-precision. The "fast" library doesn't necessarily >give less accurate results than the "accurate" library, especially if >the argument is "reasonable". The fast library is not as careful in >doing range reductions (not really an issue for ln) and errors may not >get reported properly. > >Please also indicate what version of Pascal and DIGITAL UNIX you are >using. The error can for example be seen when running the following example: (*******************************) program main(input,output); var i:integer; begin writeln('ln(2)=',ln(2):20:18); for i:=1 to 40 do writeln('i=',i:2,' 2^i=',exp(i*ln(2)):10:2); end. (******************************************) It gives the output listed at the bottom of the message. Matlab and the corresponding C-program on DEC gives ln(2)=0.69314718055995 and so does the IBM Pascal compiler on AIX. Also note that integer powers of 2 should be integers (and even numbers). I know that it is rare to depend on the accuracy above 8 significant figures, but in my case I have a sum of a lot of positive and negative numbers that almost cancel each other out. Each number is created by taking the logarithm of some numbers, doing some operations on them and then using exp() on the result. On our old IBM this program gave reliable results, but when moved to DEC the results are meaningless. I'm using OSF1 V4.0. I don't know what version of Pascal compiler it is, but it has the same age as the OS. Thank you Morten --------------------------------------------------------------------- ln(2)=0.693147182464599609 i= 1 2^i= 2.00 i= 2 2^i= 4.00 i= 3 2^i= 8.00 i= 4 2^i= 16.00 i= 5 2^i= 32.00 i= 6 2^i= 64.00 i= 7 2^i= 128.00 i= 8 2^i= 256.00 i= 9 2^i= 512.00 i=10 2^i= 1024.00 i=11 2^i= 2048.00 i=12 2^i= 4096.00 i=13 2^i= 8192.00 i=14 2^i= 16384.00 i=15 2^i= 32767.98 i=16 2^i= 65536.00 i=17 2^i= 131072.06 i=18 2^i= 262144.00 i=19 2^i= 524287.78 i=20 2^i=1048576.00 i=21 2^i=2097153.00 i=22 2^i=4194304.00 i=23 2^i=8388604.50 i=24 2^i=16777216.00 i=25 2^i=33554448.00 i=26 2^i=67108928.00 i=27 2^i=134217672.00 i=28 2^i=268435456.00 i=29 2^i=536871168.00 i=30 2^i=1073740864.00 i=31 2^i=2147482752.00 i=32 2^i=4294967808.00 i=33 2^i=8589939712.00 i=34 2^i=17179887616.00 i=35 2^i=34359724032.00 i=36 2^i=68719484928.00 i=37 2^i=137439035392.00 i=38 2^i=274877661184.00 i=39 2^i=549755584512.00 i=40 2^i=1099511758848.00