Path: utzoo!utgpu!watserv1!watmath!maytag!vlsi!watale!sunee!avadekar From: avadekar@sunee.waterloo.edu (Ashok Vadekar) Newsgroups: comp.sys.amiga Subject: Re: scanf() and double precision numbers Message-ID: <250@sunee.waterloo.edu> Date: 30 Jan 90 18:22:10 GMT References: <73.25c20097@intersil.uucp> <1990Jan28.130653.26684@helios.physics.utoronto.ca> Reply-To: avadekar@sunee.waterloo.edu (Ashok Vadekar) Organization: U. of Waterloo, Ontario Lines: 43 In article <73.25c20097@intersil.uucp> hamilton@intersil.uucp (Fred Hamilton) writes: > >Is the scanf() function supposed to be able to handle double precision >floating points? Here's why I ask: >#include >void main() >{ > float number; > printf("Enter a number: "); > scanf("%f",&number); > printf("\nNumber was %f\n",number); >} [...] >-- >Fred Hamilton Any views, comments, or ideas expressed here >Harris Semiconductor are entirely my own. Even good ones. >Santa Clara, CA The problem you've had is, as already pointed out, the %f vs. %lf specifier. However, I have found (I think) another related problem: double x; do { printf("Enter Value: "); scanf("%lf",x); printf("Value: %G\n",x); } while (x); Try this with values in the range 2E-7 to 6E-7, and you will find that the printf is returning a value of zero. The correct results happen for values less than (about) 1.000000000000000027E-7 and greater than 5.000000000000001E-7 (I havn't checked negative numbers), but fails for values in this range. I havn't checked if this is also true using %lf or %le, nor have I found if the error is related to the ffp/ieee math library choice. Ashok Vadekar University of Waterloo In Search of Signature Waterloo, Ontario