Return to BSD News archive
Path: sserve!newshost.anu.edu.au!munnari.oz.au!constellation!osuunx.ucc.okstate.edu!moe.ksu.ksu.edu!zaphod.mps.ohio-state.edu!sdd.hp.com!think.com!mintaka.lcs.mit.edu!GRAPEVINE.LCS.MIT.EDU!ai-lab!hal.gnu.ai.mit.edu!not-for-mail From: mycroft@hal.gnu.ai.mit.edu (Charles Hannum) Newsgroups: comp.os.386bsd.questions Subject: Re: gcc compile error: enquire.c Date: 5 May 1993 05:37:56 -0400 Organization: dis Lines: 53 Message-ID: <1s81tk$ei2@hal.gnu.ai.mit.edu> References: <1993May4.111203.28674@ucthpx.uct.ac.za> <hastyC6IMpp.639@netcom.com> NNTP-Posting-Host: hal.ai.mit.edu How many times do I have to say this? Can someone please put it in a FAQ list? In article <hastyC6IMpp.639@netcom.com> hasty@netcom.com (Amancio Hasty Jr) writes: > > The problem is inaccurate rounding (in atof()) more than the lack of > digits. No. The problem is entirely in printf() (really in cvt()), NOT in atof(). I have inspected the output of atof() bit by bit, and it is well within IEEE specification. >> #define DBL_MAX 1.7976931348623157E+308 > > The correct rounding of the last three digits is 159, not 157. This is wrong. Please read the IEEE specification (again?). The digits `157' are the `best' approximation. > One value that works is > > #define DBL_MAX 1.7976931348623147E+308 > ^ was 5 This is a kluge, but it does mostly work. > gcc prints 58 for the last two digits and gas converts the number > correctly. Printing the number then puts 68 in the last 2 digits... Doesn't it strike you as a little odd that printf() generates a representation which is not even in the range of doubles? If you'd just look at the bloody code one of these days, you'd see why. details: atof("1.7976931348623157e+308") returns 0x7fefffffffffffff, which is the maximum double value and is correct. However, printf() of the previous yields `1.7976931348623168e+308', which isn't even within the floating point range. It is clearly printf() that is broken, and a quick inspection of the code is enough to determine that it uses a pessimal algorithm. I've tested atof() with many other values, and it has never been off by more than is allowed by IEEE 754 (though it is not optimal). -- \ / Charles Hannum, mycroft@ai.mit.edu /\ \ PGP public key available on request. MIME, AMS, NextMail accepted. Scheme White heterosexual atheist male (WHAM) pride!