S
Snail
Why is this:
$ perl -e 'print (int (-2.6), "\n")'
-2
Shouldn't it be -3? I thought converting from float to int is supposed
to give the integer part, which is -3, and not round towards zero, as it
seems to be doing, resulting in -2? For that matter, why does c/c++ do
this too?
Any hand calculator I've tried gives -3 for int (-2.6), like a texas
instruments graphing calc.
To it's credit, perl correctly does mod func correctly:
$ perl -e 'print (-13 % 5, "\n")'
2
Where as in c/c++ you get -3, which is mathematically incorrect. (Any
hand calculator I've tried gives 2 for the above operation.)
$ perl -e 'print (int (-2.6), "\n")'
-2
Shouldn't it be -3? I thought converting from float to int is supposed
to give the integer part, which is -3, and not round towards zero, as it
seems to be doing, resulting in -2? For that matter, why does c/c++ do
this too?
Any hand calculator I've tried gives -3 for int (-2.6), like a texas
instruments graphing calc.
To it's credit, perl correctly does mod func correctly:
$ perl -e 'print (-13 % 5, "\n")'
2
Where as in c/c++ you get -3, which is mathematically incorrect. (Any
hand calculator I've tried gives 2 for the above operation.)