avadekar@sunee.waterloo.edu (Ashok Vadekar) (01/31/90)
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 <stdio.h> >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