If the float is beyond the boundaries of integer (usually +/- 2.15e+9 = 2^31), the result of converting to integer is undefined?

CODE

unction StrToNum($Str, $Check, $Magic)
{
    $Int32Unit = 4294967296;  // 2^32

    $length = strlen($Str);
    for ($i = 0; $i < $length; $i++) {
        $Check *= $Magic;     
        if (is_float($Check)) {
            $Check = ($Check - $Int32Unit * (int) ($Check / $Int32Unit));
            $Check = ($Check < -2147483648) ? ($Check + $Int32Unit) : $Check;
        }
        $Check += ord($Str{$i});
    }
    return $Check;
}


refer to http://www.php.net/manual/en/language.types.integer.php

 

 

 


Reply