Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: Floating point modulus
On 2015-01-11 11:36:01 -0800, Bart Schaefer wrote:
> On Jan 10, 11:10pm, Bart Schaefer wrote:
> }
> } The following patch would instead silently substitute the fmod() call
> } when using the % operator on a float.
>
> Incidentally, what's a reliable test for this that could be added to
> C01arith.ztst? I worry about rounding error differing by platform:
>
> torch% print $(( 29.1 % 13.0 ))
> 3.1000000000000014
The rounding error is due to the decimal-to-binary conversions, not to
the % operation, which, if I'm not mistaken, is necessarily exact in a
floating-point system: considering x % y, if |x| < |y|, then the result
is x, which is exact; otherwise the result is a multiple of ulp(y) and
less than |y| in absolute value, thus exactly representable.
--
Vincent Lefèvre <vincent@xxxxxxxxxx> - Web: <https://www.vinc17.net/>
100% accessible validated (X)HTML - Blog: <https://www.vinc17.net/blog/>
Work: CR INRIA - computer arithmetic / AriC project (LIP, ENS-Lyon)
Messages sorted by:
Reverse Date,
Date,
Thread,
Author