Re: Division [maybe a bug]



jo opp wrote:
2008/5/11 Chris W <2wsxdr5@xxxxxxx>:
jo opp wrote:

Hello!

$var1= 2155243640%31104000;
$var2= 2147309244%31104000;

echo $var1 // Return -24651656
echo $var2 // Return 1133244

$var2 return the correct result, but $var1 is wrong (the correct
result is 9067640)

Probably because the maximum signed 32 bit integer value is
2,147,483,648


OK, but with bigger numbers works fine again.
Right now I made a function to deal with this issue:

function remainder($dividend,$divisor){
$remainder= $dividend-(floor($dividend/$divisor)*$divisor);
return $remainder;
}

What do you think about it?


That will convert the numbers to floating point, which will give you round off error if the numbers get too big.

--
Chris W
KE5GIX

"Protect your digital freedom and privacy, eliminate DRM,
learn more at http://www.defectivebydesign.org/what_is_drm";

Ham Radio Repeater Database.
http://hrrdb.com
.



Relevant Pages

  • Re: Division [maybe a bug]
    ... echo $var1 // Return -24651656 ... $var2 return the correct result, but $var1 is wrong (the correct ... "Protect your digital freedom and privacy, eliminate DRM, ...
    (php.general)
  • Re: Echo to column position
    ... specific column positions consistently? ... I've got VAR1 & VAR2 that can ... echo using tabs or spaces, but this shifts the VAR2 position a bit ... depending on the value in VAR1. ...
    (microsoft.public.windows.server.scripting)
  • Re: [PHP] string as file
    ... This is an example of $var1 and $var2. ... echo include 'template.php'; ... "Some men are born to greatness, some achieve greatness, ...
    (php.general)
  • Re: Division [maybe a bug]
    ... jo opp wrote: ... echo $var1 // Return -24651656 ... $var2 return the correct result, but $var1 is wrong (the correct ...
    (php.general)
  • Re: Not memorizing an output of a function
    ... variables var1 and var2. ... but MLint should warn the user to control this manually. ... I would probably also explain, with a short comment, why you're suppressing M-Lint ...
    (comp.soft-sys.matlab)