aboutsummaryrefslogtreecommitdiff
path: root/llimits.h
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2015-02-05 15:15:33 -0200
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2015-02-05 15:15:33 -0200
commitc8d6cb01365780367f949a94b29bb3f043744c0e (patch)
tree7a70fb480a12b656771efcea82ea07ac9c863d3a /llimits.h
parent0edcdf49c00b70986f3efc12ceae912db2361d67 (diff)
downloadlua-c8d6cb01365780367f949a94b29bb3f043744c0e.tar.gz
lua-c8d6cb01365780367f949a94b29bb3f043744c0e.tar.bz2
lua-c8d6cb01365780367f949a94b29bb3f043744c0e.zip
macros 'luai_num*' (for float arithmetic operations) moved to
llimits.h.
Diffstat (limited to 'llimits.h')
-rw-r--r--llimits.h49
1 files changed, 48 insertions, 1 deletions
diff --git a/llimits.h b/llimits.h
index 921d058e..c88fd06f 100644
--- a/llimits.h
+++ b/llimits.h
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: llimits.h,v 1.128 2015/01/16 15:41:03 roberto Exp roberto $ 2** $Id: llimits.h,v 1.129 2015/01/16 17:15:52 roberto Exp roberto $
3** Limits, basic types, and some other 'installation-dependent' definitions 3** Limits, basic types, and some other 'installation-dependent' definitions
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -243,6 +243,53 @@ typedef unsigned long Instruction;
243 243
244 244
245/* 245/*
246** The luai_num* macros define the primitive operations over numbers.
247*/
248
249/* floor division (defined as 'floor(a/b)') */
250#if !defined(luai_numidiv)
251#define luai_numidiv(L,a,b) ((void)L, l_mathop(floor)(luai_numdiv(L,a,b)))
252#endif
253
254/* float division */
255#if !defined(luai_numdiv)
256#define luai_numdiv(L,a,b) ((a)/(b))
257#endif
258
259/*
260** module: defined as 'a - floor(a/b)*b'; the previous definition gives
261** NaN when 'b' is huge, but the result should be 'a'. 'fmod' gives the
262** result of 'a - trunc(a/b)*b', and therefore must be corrected when
263** 'trunc(a/b) ~= floor(a/b)'. That happens when the division has a
264** non-integer negative result, which is equivalent to the test below
265*/
266#if !defined(luai_nummod)
267#define luai_nummod(L,a,b,m) \
268 { (m) = l_mathop(fmod)(a,b); if ((m)*(b) < 0) (m) += (b); }
269#endif
270
271/* exponentiation */
272#if !defined(luai_numpow)
273#define luai_numpow(L,a,b) ((void)L, l_mathop(pow)(a,b))
274#endif
275
276/* the others are quite standard operations */
277#if !defined(luai_numadd)
278#define luai_numadd(L,a,b) ((a)+(b))
279#define luai_numsub(L,a,b) ((a)-(b))
280#define luai_nummul(L,a,b) ((a)*(b))
281#define luai_numunm(L,a) (-(a))
282#define luai_numeq(a,b) ((a)==(b))
283#define luai_numlt(a,b) ((a)<(b))
284#define luai_numle(a,b) ((a)<=(b))
285#define luai_numisnan(a) (!luai_numeq((a), (a)))
286#endif
287
288
289
290
291
292/*
246** macro to control inclusion of some hard tests on stack reallocation 293** macro to control inclusion of some hard tests on stack reallocation
247*/ 294*/
248#if !defined(HARDSTACKTESTS) 295#if !defined(HARDSTACKTESTS)