Statement on glibc/iconv Vulnerability

Voting

: seven plus two?
(Example: nine)

The Note You're Voting On

greene dot mc at removethispart dot gmail dot com
15 years ago
I believe this behavior of the floor function was intended. Note that it says "the next lowest integer". -1 is "higher" than -1.6. As in, -1 is logically greater than -1.6. To go lower the floor function would go to -2 which is logically less than -1.6.

Floor isn't trying to give you the number closest to zero, it's giving you the lowest bounding integer of a float.

In reply to Glen who commented:
Glen
01-Dec-2007 04:22
<?php
echo floor(1.6); // will output "1"
echo floor(-1.6); // will output "-2"
?>

instead use intval (seems to work v5.1.6):

<?php
echo intval(1.6); // will output "1"
echo intval(-1.6); // will output "-1"
?>

<< Back to user notes page

To Top