Reliability of `bc' (or: is `bc' buggy?)
David Mosberger
david at glance.ch
Fri Mar 1 20:36:06 AEST 1991
A little test program to check a 64 bit division algorithm with `bc'
unexpectedly turned into a test program for `bc' itself (after I found
two bugs in my program :-).
Below I have included a short `bc' program. I ran the program on
both, a UNIX System V.3/386 machine and a Ultrix 4.1 RISC machine. The
results are different, but they have one thing in common: they are wrong!
Does anybody know more about the reliability of `bc,' and what
may cause these strange results with control characters in the output?
Unfortunately, I have no access to the source of `bc' so I can only wonder
about the results...
Any info is appreciated!
--dave
<--- bug.bc ---><--- bug.bc ---><--- bug.bc ---><--- bug.bc --->
obase=16
ibase=16
x=1A8F5C99605AE52 /* dividend */
y=BB0B404 /* divisor */
q=245A07AD /* (correct) quotient */
r=147EB9E /* (correct) remainder */
x /* output numbers just to be sure... */
y
q
r
x/y /* watch this result! */
x%y /* watch this result! */
y*q+r /* check quotient & remainder */
/*
* Do the same thing in base 10:
*/
ibase=A
obase=10
x /* output numbers just to be sure... */
y
q
r
x/y /* watch this result! */
x%y /* watch this result! */
y*q+r /* check quotient & remainder */
<--- bug.bc ---><--- bug.bc ---><--- bug.bc ---><--- bug.bc --->
Output of bc running on a DECstation 5100 with Ultrix 4.1:
==========================================================
Note: First 8 columns on every line were added manually...
x => 1A8F5C99605AE52
y => BB0B404
q => 245A07AD
r => 147EB9E
x/y => 2459F81V
x%y => :l0^B^@
/* <= ^B^@ represents ASCII STX and NUL, I replaced them
by the printable characters in order to get them through
the mailer */
y*q+r => 1A8F5C99605AE52
x => 119615636279504466
y => 196129796
q => 609879981
r => 21490590
x/y => 609880-390-106
x%y => :l0^B^@ /* see note above... */
y*q+r => 119615636279504466
Output of bc running on a 386 box with SCO ODT 1.0 (System 5.3):
================================================================
Note: First 8 columns on every line were added manually...
x => 1A8F5C99605AE52
y => BB0B404
q => 245A07AD
r => 147EB9E
x/y => 2459FF57
x%y => 65F84F6
y*q+r => 1A8F5C99605AE52
x => 119615636279504466
y => 196129796
q => 609879981
r => 21490590
x/y => 609880-2247 /* certainly a strange result... */
x%y => 106923254
y*q+r => 119615636279504466
--
David Mosberger Glance Ltd.
david at glance.ch Gewerbestrasse 4
UUCP: {...}!{uunet,mcsun}!vichy!david 8162 Steinmaur
X.400: S=david;O=glance;P=switch;A=arCom;C=ch Switzerland
More information about the Comp.unix.internals
mailing list