One of my co-workers, a Clipper-programmer, ran into a really weird bug/problem in a billing-program he wrote, after he received a complaint from one of the customers.
The software does some calculations based on orders, and generates and prints a bill automatically.
Because of strict coding-rules every single result of the calculation is declared integer.
All goes well, until the result of the calculation becomes '1645'.
When the number '1645' (without decimals) is declared integer, it returns '1644' !
First we thought it was a coding-problem, and tried several combinations of numbers to check if the formula used is not buggy. After running several tests the formula was found to be OK, but, the problem occurs again with this 'magic' number 1645.
To test if the bug is not in the Clipper-compiler, we tried the same thing with a simple PHP script, on a different PC.
And again : when 1645 is declared integer, it returns 1644...
Since both PC's have an Intel Pentium processor, we thought it could be a kind of overflow-bug in the Pentium instruction-set, so we tried the same on a PC with an AMD processor.
And again, in the PHP-script running on an AMD based PC this time, we declare 1645 as integer, and it returns, you can already guess, 1644 !?!
So it cannot be a bug in the Intel or AMD chipset, nor in the Clipper compiler, nor in PHP.
To test this problem we used following PHP-code, using the exact same calculation that generated the errornous number :
<?php
$x = 2516.70;
$y = 871.70;
$z = $x - $y;
echo "\$x = ".$x." ; \$y = ".$y."<br>";
echo "\$z = \$x - \$y = ".$z."<br>";
settype ($z ,"integer");
echo "\$z as integer becomes ".$z."<br>";
?>
The result of $x minus $y becomes $z (1645), and this displays right.
But, when we declare $z to be integer, it suddenly becomes 1644.
We searched the net to check if there is some documentation on this bug, but we did not find a single thing.
Anybody got a clue ?