diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2014-11-21 10:15:00 -0200 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2014-11-21 10:15:00 -0200 |
commit | 049cf14cf9f82a07387df4d0c9bdba5ba2fef22f (patch) | |
tree | 8f8ab9e865710858c816bef0f45db94a26a48a2b /luaconf.h | |
parent | 5d628519d37a70b56be610cc4c256b3accc2f72c (diff) | |
download | lua-049cf14cf9f82a07387df4d0c9bdba5ba2fef22f.tar.gz lua-049cf14cf9f82a07387df4d0c9bdba5ba2fef22f.tar.bz2 lua-049cf14cf9f82a07387df4d0c9bdba5ba2fef22f.zip |
'x//y' extended to floats + more comments about module and floor
division operations
Diffstat (limited to 'luaconf.h')
-rw-r--r-- | luaconf.h | 18 |
1 files changed, 16 insertions, 2 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: luaconf.h,v 1.227 2014/11/02 19:35:39 roberto Exp roberto $ | 2 | ** $Id: luaconf.h,v 1.228 2014/11/19 15:00:42 roberto Exp roberto $ |
3 | ** Configuration file for Lua | 3 | ** Configuration file for Lua |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -468,9 +468,23 @@ | |||
468 | /* the following operations need the math library */ | 468 | /* the following operations need the math library */ |
469 | #if defined(lobject_c) || defined(lvm_c) | 469 | #if defined(lobject_c) || defined(lvm_c) |
470 | #include <math.h> | 470 | #include <math.h> |
471 | |||
472 | /* floor division (defined as 'floor(a/b)') */ | ||
473 | #define luai_numidiv(L,a,b) ((void)L, l_mathop(floor)((a)/(b))) | ||
474 | |||
475 | /* | ||
476 | ** module: defined as 'a - floor(a/b)*b'; the previous definition gives | ||
477 | ** NaN when 'b' is huge, but the result should be 'a'. 'fmod' gives the | ||
478 | ** result of 'a - trunc(a/b)*b', and therefore must be corrected when | ||
479 | ** 'trunc(a/b) ~= floor(a/b)'. That happens when the division has a | ||
480 | ** non-integer negative result, which is equivalent to the test below | ||
481 | */ | ||
471 | #define luai_nummod(L,a,b,m) \ | 482 | #define luai_nummod(L,a,b,m) \ |
472 | { (m) = l_mathop(fmod)(a,b); if ((m) != 0 && (a)*(b) < 0) (m) += (b); } | 483 | { (m) = l_mathop(fmod)(a,b); if ((m)*(b) < 0) (m) += (b); } |
484 | |||
485 | /* exponentiation */ | ||
473 | #define luai_numpow(L,a,b) ((void)L, l_mathop(pow)(a,b)) | 486 | #define luai_numpow(L,a,b) ((void)L, l_mathop(pow)(a,b)) |
487 | |||
474 | #endif | 488 | #endif |
475 | 489 | ||
476 | /* these are quite standard operations */ | 490 | /* these are quite standard operations */ |