Blame FAQ

Packit 70b277
Because of frequent questions ....... here is the BC FAQ
Packit 70b277
Packit 70b277
Packit 70b277
1) Why does BC have its own arbitrary precision number routines 
Packit 70b277
   (found in lib/number.c) rather than using GMP?
Packit 70b277
Packit 70b277
GMP has "integers" (no digits after a decimal), "rational numbers"
Packit 70b277
(stored as 2 integers) and "floats".  None of these will correctly
Packit 70b277
represent a POSIX BC number.  Floats are the closest, but will not
Packit 70b277
behave correctly for many computations.  For example, BC numbers have
Packit 70b277
a "scale" that represent the number of digits to represent after the
Packit 70b277
decimal point.  The multiplying two of these numbers requires one to
Packit 70b277
calculate an exact number of digits after the decimal point regardless
Packit 70b277
of the number of digits in the integer part.  GMP floats have a
Packit 70b277
"fixed, but arbitrary" mantissa and so multiplying two floats will end
Packit 70b277
up dropping digits BC must calculate.
Packit 70b277
Packit 70b277
2) The code "ibase=16; obase=10; FF" outputs FF, not 255.  Isn't this
Packit 70b277
   a bug?
Packit 70b277
Packit 70b277
No.  ibase changed the input base at that point.  The 10 is then in
Packit 70b277
base 16 and thus is the value 16.  Therefore, both ibase and obase
Packit 70b277
are 16 (decimal).  And FF (base 16) on input is printed as FF (base 16)
Packit 70b277
on output.  So how can one get 255?  First, single digit numbers are
Packit 70b277
not converted using ibase.  So A is always 10 (decimal).  The following
Packit 70b277
code will always work.  "ibase=F+1; obase=A; FF" and that always prints
Packit 70b277
255.
Packit 70b277
Packit 70b277
3) Why is the scale variable ignored on multiply?
Packit 70b277
Packit 70b277
That is the way POSIX specifics multiply.  Reread the documentation for
Packit 70b277
the multiply operation and see that multiply uses the scales of the
Packit 70b277
numbers multiplied to determine the scale of the result.
Packit 70b277
Packit 70b277
4) bc's mod command is not working when I run with "bc -l".
Packit 70b277
Packit 70b277
bc's mod (%) command works like integer remainder when scale is 0.
Packit 70b277
The -l flag sets scale to 20 and that chanes how a % b is computed.
Packit 70b277
Read the man page for exact details.
Packit 70b277