Bug #14278: % and / bug with INTEGERs!

From: Date: Thu, 29 Nov 2001 10:27:52 +0000
Subject: Bug #14278: % and / bug with INTEGERs!
Groups: php.dev 
Request: Send a blank email to php-dev+get-71994@lists.php.net to get a copy of this message
From:             pumuckel@metropolis.de
Operating system: Linux 2.2.19
PHP version:      4.0.6
PHP Bug Type:     Math related
Bug description:  % and / bug with INTEGERs!

Sometimes (1 - 10 times a day) I get a strange error on one of my
production servers. See this function:

function MakeHash($num) {
  $ret = "";
  $ca = array();
  for ($i = 0; $i < 6; $i++) {
    $c = $num % 26;
    $ca[] = "$num $c";   
    $ret = sprintf("%c", 65+$c).$ret;
    $num = ($num-$c)/ 26;
  }
  // Send $ca array via email to me.... (removed)
  return $ret;
}

Sometimes calling this function with an INT it calculates wired results...
If that happens I mail the $ca array to myself and see what it does:

101110 19          (MEANS: 101110 % 26 is 19!? That's wrong, it is 22)
38888588 24       (MEANS 101110 / 26 is 38888588, but it is 3888)
1495714 12        ...
57527 15
2212 2
85 7

What goes wrong? In the beginning the % result is wrong, and then the
division result is wrong too...  any suggestions!?

 /mike
-- 
Edit bug report at: http://bugs.php.net/?id=14278&edit=1



Thread (4 messages)

« previous php.dev (#71994) next »