PHP and big numbers

One would expect, that one of the most used script languages of the world would be ableto do proper comparisons of numbers, even big numbers, right?Well, PHP is not such a language, at least not on 32bit systems.Given a script like this:

<?

$t1 = “1244431010010381771”;

$t2 = “1244431010010381772”;

if ($t1 == $t2) {

    print “equal\n”;

}

?>

A current PHP version will output:

schoenfeld@homer ~ % php5 test.php
equal

It will do the right thing on 64bit systems (not claiming that the numbers are equal).Interesting enough: An equal-type-equality check (see my article from a few years ago) will not tell that the two numbers are equal.

2 Gedanken zu „PHP and big numbers“

  1. Well, no, not really. As the string does not store anything except numbers PHP will coerce it into a numeric data type, which makes perfect sense due to the nature of the PHP type handling.

Hinterlasse eine Antwort

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind markiert *