According to bc
manual
expr % expr The result of the expression is the "remainder" and it is computed in the following way. To compute a%b, first a/b is computed to scale digits. That result is used to compute a-(a/b)*b to the scale of the maximum of scale+scale(b) and scale(a). If scale is set to zero and both expressions are integers this expression is the integer remainder function.
So what happens, he tries to evaluate a-(a/b)*b
using the current scale
settings. The default value of scale
is 0, so you get the remainder. When you run bc -l
, you get scale=20
, and the expression a-(a/b)*b
evaluates to zero when using 20 fractional digits.
To find out how this works, try other fractions:
$ bc -l 1%3 .00000000000000000001
To make a long story short, simply compare three outputs:
By default, scale
with -l
(20) enabled:
scale 20 3%5 0 1%4 0
Set scale
to 1:
scale=1 3%5 0 1%4 .2
Or to zero (by default without -l
):
scale=0 3%5 3 1%4 1
source share