[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: [ANN] Lua 5.4.0 (work2) now available
- From: Roberto Ierusalimschy <roberto@...>
- Date: Fri, 24 Aug 2018 15:15:49 -0300
> Lua does use fmod but it doesn't have exactly the same semantics. See the comment on luai_nummod on limits.h for details.
More exactly, Lua uses this definition:
{ (m) = l_mathop(fmod)(a,b); if ((m)*(b) < 0) (m) += (b); }
The correction is due to fmod assumes a rounding towards zero in
the division, while Lua rounds towards minus infinite. But the test
adds little to the cost; 'fmod' is the expensive operation here.
Earlier Lua versions used the mathematical definition:
(m) = ((a) - l_mathop(floor)((a)/(b))*(b))
It is *much* faster than 'fmod', but it gives NaN when 'b' is infinite
(it should give 'a'). I am not sure whether there are other problematic
cases besides 'b' being inf or -inf.
-- Roberto