3b1 ulrem() bug
Beuning
bgb at ihlpg.ATT.COM
Wed Jul 20 10:18:27 AEST 1988
3b1 owners,
I believe I have found a bug in unsigned long
remainder arithmetic. If you compile and execute this
program on your 3b1, the value of 'c' is incorrect.
----------------------------------------------------------------
main()
{
unsigned int a = 5 * 536870912;
unsigned int b = 1073741823;
unsigned int c, d;
c = a % b;
/* slow but sure method */
d = a;
while( d >= b )
d -= b;
printf( "a = %u b = %u c = %u d = %u\n", a, b, c, d );
exit( 0 );
}
----------------------------------------------------------------
The output on my 3b1 is (commas added for readability)
a = 2,684,354,560 b = 1,073,741,823 c = 1,610,612,737 d = 536,870,914
The value of 'd' is correct, the value of 'c' is incorrect.
An "unsigned int" should be able to contain all values
from 0 to 4,294,967,295 (2 ^ 32 - 1).
The line that reads "c = a % b" generates assembly code
that calls the ulrem() function to compute the remainder.
It looks like there is a bug in ulrem(). I have only seen
the problem with very large numbers.
Brian Beuning
..!ihnp4ihlpn!bgb
More information about the Unix-pc.general
mailing list