php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #20102 wrong value on mod (%) function
Submitted: 2002-10-26 03:19 UTC Modified: 2002-10-26 14:37 UTC
From: hermawan at dmonster dot com Assigned:
Status: Not a bug Package: *Math Functions
PHP Version: 4.2.3 OS: Redhat Linux 7.3
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem:
8 + 44 = ?
Subscribe to this entry?

 
 [2002-10-26 03:19 UTC] hermawan at dmonster dot com
When I try to mod some integer, it returns false value, it's different with the calculator. Here is the example :

<?php
  $int = 700000000;
  $modwith = 1000000000000;
  print $int%$modwith; // it return 700000000
                       // this is correnct.
  $int = 800000000;
  print $int%$modwith; // it return 72620032
                       // this is false, it supposed to be 800000000
?> 

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2002-10-26 12:06 UTC] hholzgra@php.net
your $modwidth value is way beyond the 
usable and valid range (unless you are
on a 64bit system ;)
 [2002-10-26 12:15 UTC] hermawan at dmonster dot com
I found the replacement of mod (%) which can be used with out of range value. The function is :

    function mod ($a, $b) {
      $rtn = $a;
      while ($rtn > $b) {
         $rtn -= $b;
      }
      return $rtn;
    }

It works with my other script and returning the correct value. Please try it.
 [2002-10-26 14:37 UTC] hholzgra@php.net
try 

<?php
  $modwith = 1000000000000;
  echo gettype($modwith);
?>

see?
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Mar 28 11:01:27 2024 UTC