in reply to Re^2: Floating point problems
in thread Floating point problems
Am I asking too much if I see something prints 3 the int of that to be 3 ?
In a word: yes.
int has a very clearly defined meaning: truncate to an integer. And that behaviour is required for many algorithms.
It never "rounds-up" as print does:
printf( "%.16f ", 3-$_ ), print 3-$_ for map 10**-$_, 1 .. 16;; 2.8999999999999999 2.9 2.9900000000000002 2.99 2.9990000000000001 2.999 2.9998999999999998 2.9999 2.9999899999999999 2.99999 2.9999989999999999 2.999999 2.9999999000000002 2.9999999 2.9999999900000001 2.99999999 2.9999999989999999 2.999999999 2.9999999999000000 2.9999999999 2.9999999999900000 2.99999999999 2.9999999999989999 2.999999999999 2.9999999999999001 2.9999999999999 2.9999999999999898 2.99999999999999 2.9999999999999991 3 3.0000000000000000 3
If you want rounding behaviour rather than truncation, use an appropriate function or module.
|
---|