Debian Codegraph @

FAQ

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