#20102 [Bgs]: wrong value on mod (%) function

From: Date: Sat, 26 Oct 2002 19:37:16 +0000
Subject: #20102 [Bgs]: wrong value on mod (%) function
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-23389@lists.php.net to get a copy of this message
ID: 20102 Updated by: hholzgra@php.net Reported By: hermawan@dmonster.com Status: Bogus Bug Type: *Math Functions Operating System: Redhat Linux 7.3 PHP Version: 4.2.3 New Comment: try <?php $modwith = 1000000000000; echo gettype($modwith); ?> see? Previous Comments: ------------------------------------------------------------------------ [2002-10-26 12:15:36] hermawan@dmonster.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 12:06:51] hholzgra@php.net your $modwidth value is way beyond the usable and valid range (unless you are on a 64bit system ;) ------------------------------------------------------------------------ [2002-10-26 03:19:18] hermawan@dmonster.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 ?> ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=20102&edit=1

« previous php.bugs (#23389) next »