aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2010-05-10 13:38:58 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2010-05-10 13:38:58 -0300
commita48e330f37c06ec733234f96421a17e89ec61145 (patch)
tree884b9735d7074dac801de38dcf075aa644859e79
parentdcc070683cf89d82aae4f2cbe00ff8dbd97392ca (diff)
downloadlua-a48e330f37c06ec733234f96421a17e89ec61145.tar.gz
lua-a48e330f37c06ec733234f96421a17e89ec61145.tar.bz2
lua-a48e330f37c06ec733234f96421a17e89ec61145.zip
macros 'lua_number2int' and 'lua_number2uint' for Visual Studio
corrected and tested
-rw-r--r--luaconf.h23
1 files changed, 12 insertions, 11 deletions
diff --git a/luaconf.h b/luaconf.h
index a9a7e53f..3ede4e8c 100644
--- a/luaconf.h
+++ b/luaconf.h
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: luaconf.h,v 1.134 2010/03/03 18:53:02 roberto Exp roberto $ 2** $Id: luaconf.h,v 1.135 2010/03/26 20:58:11 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*/
@@ -440,17 +440,18 @@
440/* On a Microsoft compiler, use assembler */ 440/* On a Microsoft compiler, use assembler */
441#if defined(_MSC_VER) 441#if defined(_MSC_VER)
442 442
443#define lua_number2int(i,d) {__asm fld d __asm fistp i} 443#define lua_number2int(i,n) __asm {__asm fld n __asm fistp i}
444#define lua_number2integer(i,n) lua_number2int(i, n) 444#define lua_number2integer(i,n) lua_number2int(i, n)
445#define lua_number2uint(i,n) lua_number2int(i, n) 445#define lua_number2uint(i,n) \
446 {__int64 l; __asm {__asm fld n __asm fistp l} i = (unsigned int)l;}
446 447
447#else 448#else
448/* the next trick should work on any Pentium, but sometimes clashes 449/* the next trick should work on any Pentium, but sometimes clashes
449 with a DirectX idiosyncrasy */ 450 with a DirectX idiosyncrasy */
450 451
451union luai_Cast { double l_d; long l_l; }; 452union luai_Cast { double l_d; long l_l; };
452#define lua_number2int(i,d) \ 453#define lua_number2int(i,n) \
453 { volatile union luai_Cast u; u.l_d = (d) + 6755399441055744.0; (i) = u.l_l; } 454 { volatile union luai_Cast u; u.l_d = (n) + 6755399441055744.0; (i) = u.l_l; }
454#define lua_number2integer(i,n) lua_number2int(i, n) 455#define lua_number2integer(i,n) lua_number2int(i, n)
455#define lua_number2uint(i,n) lua_number2int(i, n) 456#define lua_number2uint(i,n) lua_number2int(i, n)
456 457
@@ -459,9 +460,9 @@ union luai_Cast { double l_d; long l_l; };
459 460
460#else 461#else
461/* this option always works, but may be slow */ 462/* this option always works, but may be slow */
462#define lua_number2int(i,d) ((i)=(int)(d)) 463#define lua_number2int(i,n) ((i)=(int)(n))
463#define lua_number2integer(i,d) ((i)=(LUA_INTEGER)(d)) 464#define lua_number2integer(i,n) ((i)=(LUA_INTEGER)(n))
464#define lua_number2uint(i,d) ((i)=(unsigned LUA_INT32)(d)) 465#define lua_number2uint(i,n) ((i)=(unsigned LUA_INT32)(n))
465 466
466#endif 467#endif
467 468
@@ -484,9 +485,9 @@ union luai_Cast { double l_d; long l_l; };
484#include <float.h> 485#include <float.h>
485#include <math.h> 486#include <math.h>
486 487
487#define luai_hashnum(i,d) { int e; \ 488#define luai_hashnum(i,n) { int e; \
488 d = frexp(d, &e) * (lua_Number)(INT_MAX - DBL_MAX_EXP); \ 489 n = frexp(n, &e) * (lua_Number)(INT_MAX - DBL_MAX_EXP); \
489 lua_number2int(i, d); i += e; } 490 lua_number2int(i, n); i += e; }
490 491
491#endif 492#endif
492 493