From: 7willows at dsl dot pipex dot com Operating system: SunOS ts10 5.11 snv_115 i86pc PHP version: 5.2.10 PHP Bug Type: Math related Bug description: multiplication by zero problem
Description: ------------ I have a function which is used to assign values into a number of global arrays. Two of the arrays are assigned values that are generated using the rand() function. A third array holds the result of the multiplication. When both first two arrays are assigned a value of 0 (zero), the result of the multiplication is 1 and not 0. This information is then entered into a html form and presented to the user and they are asked to enter the results of $numfacttest[$a] / $randval[$a] = useranswer The useranswer is then compared to $answer[$a] which is already calculated. The problem is that 0 * 0 is returning the answer 1 sometimes. Reproduce code: --------------- function setnumberfacttest($count,$maxnumberfacts) { global $numfacttest, $answer, $operator, $randval; for ($a=0 ; $a < $count ; $a++) { $operator[a]=chr(247); $bit1=rand(0,$maxnumberfacts); $bit2=rand(0,$maxnumberfacts); $numfacttest[$a]=$bit1 * $bit2; $randval[$a]=$bit2; $answer[$a]=$bit1; } } Expected result: ---------------- Actual Results with hidden value displayed 2 / 1 = <useranswer> 2 0 / 0 = <useranswer> 0 0 / 0 = <useranswer> 0 2 / 2 = <useranswer> 1 4 / 2 = <useranswer> 2 1 / 1 = <useranswer> 1 0 / 0 = <useranswer> 0 0 / 0 = <useranswer> 0 0 / 0 = <useranswer> 0 1 / 1 = <useranswer> 1 Actual result: -------------- Actual Results with calculated hidden value displayed 2 / 1 = <useranswer> 2 0 / 0 = <useranswer> 1 0 / 0 = <useranswer> 0 2 / 2 = <useranswer> 1 4 / 2 = <useranswer> 2 1 / 1 = <useranswer> 1 0 / 0 = <useranswer> 1 0 / 0 = <useranswer> 0 0 / 0 = <useranswer> 2 1 / 1 = <useranswer> 1 -- Edit bug report at http://bugs.php.net/?id=48904&edit=1 -- Try a CVS snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=48904&r=trysnapshot52 Try a CVS snapshot (PHP 5.3): http://bugs.php.net/fix.php?id=48904&r=trysnapshot53 Try a CVS snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=48904&r=trysnapshot60 Fixed in CVS: http://bugs.php.net/fix.php?id=48904&r=fixedcvs Fixed in CVS and need be documented: http://bugs.php.net/fix.php?id=48904&r=needdocs Fixed in release: http://bugs.php.net/fix.php?id=48904&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=48904&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=48904&r=needscript Try newer version: http://bugs.php.net/fix.php?id=48904&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=48904&r=support Expected behavior: http://bugs.php.net/fix.php?id=48904&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=48904&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=48904&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=48904&r=globals PHP 4 support discontinued: http://bugs.php.net/fix.php?id=48904&r=php4 Daylight Savings: http://bugs.php.net/fix.php?id=48904&r=dst IIS Stability: http://bugs.php.net/fix.php?id=48904&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=48904&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=48904&r=float No Zend Extensions: http://bugs.php.net/fix.php?id=48904&r=nozend MySQL Configuration Error: http://bugs.php.net/fix.php?id=48904&r=mysqlcfg