Statement on glibc/iconv Vulnerability

Voting

: seven plus one?
(Example: nine)

The Note You're Voting On

till at tonda dot de
10 years ago
Note that the use of floor may (intended or not) uncover false integers:

<?php

$arrRoots
=array();
$arrRoots[]=pow(27,(1/3)); // pow(3,3)=27
$arrRoots[]=pow(64,(1/3)); // pow(4,3)=64

for($i=0;$i<count($arrRoots);$i++)
{
if(
$arrRoots[$i]!=floor($arrRoots[$i]))
echo
'<div style="background-color:#ffff99">';
echo
'Unfloored value: '.$arrRoots[$i].' (Format float? '.is_float($arrRoots[$i]).')<br />';
echo
'Floored value: '.floor($arrRoots[$i]).' (Format float? '.is_float(floor($arrRoots[$i])).')';
if(
$arrRoots[$i]!=floor($arrRoots[$i]))
echo
'</div>';
echo
'<br /><br />';
}

?>

The directly retrieved cubic root of 64 (by pow with a fraction exp) equals 4; an outcome any maths teacher will reckon correct.

Yet bringing the same number - the cubic root of 64 retrieved in the very same manner - to the floor will result in a value of 3 only. This behaviour is in no way exceptional.

It is pivotal to check whether you are dealing with genuine integers or floats in disguise. floor should be used carefully.

<< Back to user notes page

To Top