php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #48904 multiplication by zero problem
Submitted: 2009-07-13 13:51 UTC Modified: 2009-07-23 01:00 UTC
Votes:1
Avg. Score:3.0 ± 0.0
Reproduced:0 of 1 (0.0%)
From: 7willows at dsl dot pipex dot com Assigned:
Status: No Feedback Package: Math related
PHP Version: 5.2.10 OS: SunOS ts10 5.11 snv_115 i86pc
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: 7willows at dsl dot pipex dot com
New email:
PHP Version: OS:

 

 [2009-07-13 13:51 UTC] 7willows at dsl dot pipex dot com
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


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2009-07-15 12:12 UTC] jani@php.net
Thank you for this bug report. To properly diagnose the problem, we
need a short but complete example script to be able to reproduce
this bug ourselves. 

A proper reproducing script starts with <?php and ends with ?>,
is max. 10-20 lines long and does not require any external 
resources such as databases, etc. If the script requires a 
database to demonstrate the issue, please make sure it creates 
all necessary tables, stored procedures etc.

Please avoid embedding huge scripts into the report.

And we really mean it: Max. 10-20 lines of code should be enough to reproduce this if it really is a bug..which I doubt.
 [2009-07-23 01:00 UTC] php-bugs at lists dot php dot net
No feedback was provided for this bug for over a week, so it is
being suspended automatically. If you are able to provide the
information that was originally requested, please do so and change
the status of the bug back to "Open".
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Apr 18 14:01:31 2024 UTC