Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

print and floating point output



Hi zshworkers again,

something that really confused me even if i understand that
floating point is a problem for a computer when converting it to binary
is the result of e.g. 
print $((2.8*16.0))
which _sadly_, i think, returns:
44.799999999999997

I wonder if it really was a good decision to print so many numbers
after the point.

When asking Sven W9y he told me that that's a problem of
gcc's printf/fprintf which indeed gives that result when using it with
more than 15 numbers after the point.

on the other hand perl, ruby and python all return
the right result:
perl -le 'print 2.8*16.0' => 44.8
python -c 'print 2.8*16.0' => 44.8
ruby -e 'puts 2.8*16.0' => 44.8

so i guess it would make a lot sense and not cause confusion if zsh
would have a more sensible output with `print' and for users
not using `printf'.


        
                Matthias



Messages sorted by: Reverse Date, Date, Thread, Author