home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.os.coherent
- Path: sparky!uunet!munnari.oz.au!penguin!brianw
- From: brianw@philips.oz.au (Brian Wallis)
- Message-ID: <1992Dec21.123913.2881@philips.oz.au>
- Date: Mon, 21 Dec 92 12:39:13 GMT
- Organization: Philips Public Telecommunications Systems, Melbourne, Australia
- Subject: Floating point: printf "%g" bug?
- Lines: 57
-
- 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?
-
- thanks, brian...
-
-
- #include <stdio.h>
-
- main(argc,argv)
- int argc;
- char *argv[];
- {
- int i;
-
- for(i=38;i<60;i++){
- printf("%d - (.13g)%.13g (.14g)%.14g\n",i,(double)i,(double)i);
- }
-
- }
- --
- -----------------------------------------------------------------
- Brian Wallis <brianw@philips.oz.au> Phone: +61 3 8813576
- Philips Public Telecommunications Systems Fax: +61 3 8813577
- Melbourne, Australia
-