home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.os.coherent
- Path: sparky!uunet!zaphod.mps.ohio-state.edu!cs.utexas.edu!torn!mcshub!csx.cciw.ca!hcp
- From: hcp@csx.cciw.ca (H.C. Pulley)
- Subject: Re: Floating point: printf "%g" bug?
- Organization: Canada Centre for Inland Waters
- Date: Tue, 22 Dec 1992 13:00:28 GMT
- Message-ID: <1992Dec22.130028.27444@csx.cciw.ca>
- References: <1992Dec21.123913.2881@philips.oz.au>
- Lines: 63
-
- In article <1992Dec21.123913.2881@philips.oz.au> brianw@philips.oz.au (Brian Wallis) writes:
- >I've come across a possible anomally in the floating point output from printf
- >in Coherent 4.0. The program to demonstrate this is appended at the end. It
- >looks to me like a rounding error.
- >
- >Here are the rusults of running the program on my system...
- >
- >
- >38 - (.13g)38 (.14g)38
- >39 - (.13g)39 (.14g)39
- >40 - (.13g)40 (.14g)40
- >41 - (.13g)41 (.14g)41.00000000000001
- >42 - (.13g)42 (.14g)42
- >43 - (.13g)43 (.14g)43
- >44 - (.13g)44 (.14g)44
- >45 - (.13g)45 (.14g)45
- >46 - (.13g)46 (.14g)46.00000000000001
- >47 - (.13g)47 (.14g)47
- >48 - (.13g)48 (.14g)48.00000000000001
- >49 - (.13g)49 (.14g)49
- >50 - (.13g)50 (.14g)50
- >51 - (.13g)51 (.14g)51.00000000000001
- >52 - (.13g)52 (.14g)52
- >53 - (.13g)53 (.14g)53.00000000000001
- >54 - (.13g)54 (.14g)54
- >55 - (.13g)55 (.14g)55
- >56 - (.13g)56 (.14g)56.00000000000001
- >57 - (.13g)57 (.14g)57
- >58 - (.13g)58 (.14g)58.00000000000001
- >59 - (.13g)59 (.14g)59
- >
- >The extra ...0001 is causing problems in my port of perl. I may have to replace
- >printf and friends, but then again perhaps the problem is in the floating point
- >itself?
- >
- >Any clues from anyone?
-
- I think the problem is just that double precision floating point IEEE format
- is not significant to the number of digits you are trying to display. If you
- try this with float instead of double you should see the same thing or worse
- (this used to happen a lot in FORTRAN with different machines having very
- different doubleprecision in the mainframe days - CDC Cybers have 128 bit
- doubles, and you wonder why your answer is not the same as the guy using the
- VAX).
-
- I am sure you know, but just like there is 1/3 = .3333333..... in decimal,
- there are non-repeating numbers in binary, octal and hex too. Numbers which
- repeat in one system, may not repeat in another.
-
- The DECVAX format used in Coherent 286 has a few more fraction bits.
-
- >thanks, brian...
-
- I hope it helps!
-
- [coding example deleted]
-
- Harry
- --
- hcp@csx.cciw.ca |This message released|It takes all kinds,
- hcpiv@grumpy.cis.uoguelph.ca |to the PUBLIC DOMAIN.|and to each his own.
- ----------------------------------+---------------------|This thought in mind,
- Stay away from the DOS side, Luke!|Un*x don't play that.|I walk alone.
-