According to the 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 is that it tries to evaluate a-(a/b)*b
using the current scale
settings. The default 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 see how it works, try some other fractions:
$ bc -l
1%3
.00000000000000000001
To make a long story short, just compare three outputs:
Default scale
with -l
enabled (20):
scale
20
3%5
0
1%4
0
Let's set scale
to 1:
scale=1
3%5
0
1%4
.2
Or to zero (default without -l
):
scale=0
3%5
3
1%4
1