|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2007-06-16 21:18 UTC] bartlomiejbak at gmail dot com
Description:
------------
Hi. I've got a little bit problem
this code should show me result of equation 20x + 27y = 1
for ($y = 0; $y < 1000; $y++)
{
$x = (1/20) - (27/20) * $y;
if ($x == intval($x)) $out .= "x: $x,y: $y\n";
}
I need only int values of X and Y but intval() sometimes return wrong value. Result should be (-4,3),(-31,23),(-58,43) etc. but php is starting showing from (-31,23)...
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sat Oct 25 13:00:01 2025 UTC |
so. if you are right look at results of this code function isInt($value) { return preg_match("/^-?[0-9]+$/",$value); } for ($y = 0; $y < 100; $y++) { $x = (1/20) - (27/20) * $y; if (isInt($x)) { echo "x = $x; intval(x) = ".intval($x)."; var_dump(x == intval(x)) = "; var_dump($x == intval($x)); echo "\n"; } } first result // x = -4; intval(x) = -4; var_dump(x == intval(x)) = bool(false) why?