Bug #15946: Math output errors

From: Date: Fri, 08 Mar 2002 03:55:19 +0000
Subject: Bug #15946: Math output errors
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-1980@lists.php.net to get a copy of this message
From: aubieweb@rogers.com Operating system: Windows 2000 PHP version: 4.1.1 PHP Bug Type: Output Control Bug description: Math output errors I wrote a script which output Pascal's triangle and then showed the numbers which were divisible by a certain number in a different colour. At first, this works fine. Then after the 20th row or so, the % operator starts outputting incorrect numbers. For example, 37 % 4 returns 1. 24 % 4 returns 3. When those numbers are checked on their own, it works fine. In the loops though, it starts giving incorrect information after 20 rows. You can see this at www.alkaline2.com/triangle.php CODE <? $rows--; for ($r = 0; $r <= $rows; $r++) { if ($hidenum) print "<table cellpadding='0' cellspacing='0' border='1' bordercolor='#000088' borderstyle='solid'><tr>\n"; if (!$hidenum) print "<table cellpadding='2' cellspacing='1' border='0'><tr>\n"; for ($i = 0; $i <= $r; $i++) { $num = factorial($r)/(factorial($r - $i) * factorial($i)); if ($divisor > 0 && $num % $divisor == 0) { $bgcolor='#ff0000'; } else { $bgcolor='#444444'; } if (!$hidenum) print "<td bgcolor='$bgcolor'><span class='text'>$num</span></td>\n"; $check = $num % $divisor; if ($hidenum && $divisor > 0 && $num % $divisor == 0) print "<td><img src='red.gif' width='$size' height='$size' alt='$num % $divisor = $check'></td>\n"; if ($hidenum && $divisor > 0 && $num % $divisor != 0) print "<td><img src='grey.gif' width='$size' height='$size' alt='$num % $divisor = $check'></td>\n"; if ($hidenum && $divisor == 0) print "<td><img src='grey.gif' width='$size' height='$size' alt='$num % $divisor = $check'></td>\n"; } print "</tr></table>"; } function factorial($x) { $total = 1; for ($i = $x; $i > 1; $i--) $total = $total * $i; return $total; } ?> -- Edit bug report at http://bugs.php.net/?id=15946&edit=1 -- Fixed in CVS: http://bugs.php.net/fix.php?id=15946&r=fixedcvs Fixed in release: http://bugs.php.net/fix.php?id=15946&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=15946&r=needtrace Try newer version: http://bugs.php.net/fix.php?id=15946&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=15946&r=support Expected behavior: http://bugs.php.net/fix.php?id=15946&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=15946&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=15946&r=submittedtwice

« previous php.bugs (#1980) next »