aboutsummaryrefslogtreecommitdiff
path: root/llimits.h
diff options
context:
space:
mode:
Diffstat (limited to 'llimits.h')
-rw-r--r--llimits.h14
1 files changed, 8 insertions, 6 deletions
diff --git a/llimits.h b/llimits.h
index 6afa8997..e91310a0 100644
--- a/llimits.h
+++ b/llimits.h
@@ -293,15 +293,17 @@ typedef unsigned long Instruction;
293#endif 293#endif
294 294
295/* 295/*
296** modulo: defined as 'a - floor(a/b)*b'; this definition gives NaN when 296** modulo: defined as 'a - floor(a/b)*b'; the direct computation
297** 'b' is huge, but the result should be 'a'. 'fmod' gives the result of 297** using this definition has several problems with rounding errors,
298** 'a - trunc(a/b)*b', and therefore must be corrected when 'trunc(a/b) 298** so it is better to use 'fmod'. 'fmod' gives the result of
299** ~= floor(a/b)'. That happens when the division has a non-integer 299** 'a - trunc(a/b)*b', and therefore must be corrected when
300** negative result, which is equivalent to the test below. 300** 'trunc(a/b) ~= floor(a/b)'. That happens when the division has a
301** non-integer negative result, which is equivalent to the tests below.
301*/ 302*/
302#if !defined(luai_nummod) 303#if !defined(luai_nummod)
303#define luai_nummod(L,a,b,m) \ 304#define luai_nummod(L,a,b,m) \
304 { (m) = l_mathop(fmod)(a,b); if ((m)*(b) < 0) (m) += (b); } 305 { (void)L; (m) = l_mathop(fmod)(a,b); \
306 if (((m) > 0) ? (b) < 0 : ((m) < 0 && (b) > 0)) (m) += (b); }
305#endif 307#endif
306 308
307/* exponentiation */ 309/* exponentiation */