[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: bc "remainder" operation malfunctions if scale!=0
From: |
Erik Rossen |
Subject: |
Re: bc "remainder" operation malfunctions if scale!=0 |
Date: |
Thu, 28 Dec 2000 23:37:04 +0100 |
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
On 27 Dec 2000, Harald Anlauf wrote:
> address@hidden (Erik Rossen) writes:
>
> > Is the following behavior normal for the remainder operation?
> >
> > bc 1.05
> > Copyright 1991, 1992, 1993, 1994, 1997, 1998 Free Software Foundation,
> > Inc.
> > This is free software with ABSOLUTELY NO WARRANTY.
> > For details type `warranty'.
> > scale=0
> > 5%4
> > 1
> > scale=6
> > 5%4
> > 0
>
> RTFM!
I thought I had.
>
> 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 inteĀ
> gers this expression is the integer remainder funcĀ
> tion.
>
> Try e.g., scale=1, and then you'll see that bc is right (this time).
Ah...I get it now (after rereading 4 times).
I was looking for a modulus operator that would work for non-whole numbers
and I didn't realise that one would have to reset scale to 0 every time I
wanted % to behave this way. When I set scale=6 in the 5%4 example above,
I was expecting 1 (short for 1.000000) as a response.
scale=0
5.5%5.4
.1
5.5%2
1.5
Yup, that's what I needed.
My apologies. To eliminate future confusion, perhaps the last line above
could be changed to:
"The scale must be set to zero to obtain the modulus operation."
?
Erik Rossen ^
address@hidden /e\
http://www.multimania.com/rossen --- GPG key ID: 2935D0B9
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.0 (GNU/Linux)
Comment: Made with pgp4pine 1.75
iD8DBQE6S8CsY88aPik10LkRAltwAKDAcIhaj6+vMv8p9TgWUNQ+vX3UogCfbi8b
iBbyfeFq34vJWoiAQ5LrACI=
=b8Kq
-----END PGP SIGNATURE-----