#41886 [NEW]: int added by float ended as not equal to float equavalent value

From: Date: Tue, 03 Jul 2007 11:42:22 +0000
Subject: #41886 [NEW]: int added by float ended as not equal to float equavalent value
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-114607@lists.php.net to get a copy of this message
From: c00lways at gmail dot com Operating system: windows xp prof sp 2 PHP version: 5.2.3 PHP Bug Type: Math related Bug description: int added by float ended as not equal to float equavalent value Description: ------------ int added by float ended as not equal to float equavalent value Reproduce code: --------------- //this output <empty>, not 1 echo isValidRange( 5.23, 1, 10, 0.01 ); //this output 1 //echo 5.23 == (1+4.23); function isValidRange( $p_value, $p_start, $p_end, $p_step=1 ) { //reverse step if( $p_end < $p_start ) { $p_step = -($p_step); } if( $p_step == 0.000000 ) { raiseError(1, "Invalid step: " . $p_step); } for( $c = $p_start; $c <= $p_end; $c+=$p_step ) { //this part caused the problem if( $p_value == $c ) { return true; } //if change it to //if( $p_value."" == $c."" ) // then it works! return true } return false; } Expected result: ---------------- 1 Actual result: -------------- <empty> -- Edit bug report at http://bugs.php.net/?id=41886&edit=1 -- Try a CVS snapshot (PHP 4.4): http://bugs.php.net/fix.php?id=41886&r=trysnapshot44 Try a CVS snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=41886&r=trysnapshot52 Try a CVS snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=41886&r=trysnapshot60 Fixed in CVS: http://bugs.php.net/fix.php?id=41886&r=fixedcvs Fixed in release: http://bugs.php.net/fix.php?id=41886&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=41886&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=41886&r=needscript Try newer version: http://bugs.php.net/fix.php?id=41886&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=41886&r=support Expected behavior: http://bugs.php.net/fix.php?id=41886&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=41886&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=41886&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=41886&r=globals PHP 3 support discontinued: http://bugs.php.net/fix.php?id=41886&r=php3 Daylight Savings: http://bugs.php.net/fix.php?id=41886&r=dst IIS Stability: http://bugs.php.net/fix.php?id=41886&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=41886&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=41886&r=float No Zend Extensions: http://bugs.php.net/fix.php?id=41886&r=nozend MySQL Configuration Error: http://bugs.php.net/fix.php?id=41886&r=mysqlcfg

« previous php.bugs (#114607) next »