aboutsummaryrefslogtreecommitdiff
path: root/lmathlib.c
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2024-06-20 14:46:06 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2024-06-20 14:46:06 -0300
commita08d82eb132bfd9db5b91e0d5ebcb81d7b26dcd0 (patch)
tree45618815246686a535a28fb4e6f9736a60be00d4 /lmathlib.c
parent55ac40f859ad8e28fe71a8801d49f4a4140e8aa3 (diff)
downloadlua-a08d82eb132bfd9db5b91e0d5ebcb81d7b26dcd0.tar.gz
lua-a08d82eb132bfd9db5b91e0d5ebcb81d7b26dcd0.tar.bz2
lua-a08d82eb132bfd9db5b91e0d5ebcb81d7b26dcd0.zip
llimits.h being used by all Lua code
The definitions in llimits.h are useful not only for the core. That header only defines types and '#define's, so libs and core still do not share any real code/data.
Diffstat (limited to 'lmathlib.c')
-rw-r--r--lmathlib.c21
1 files changed, 7 insertions, 14 deletions
diff --git a/lmathlib.c b/lmathlib.c
index c1041f37..2bdcb637 100644
--- a/lmathlib.c
+++ b/lmathlib.c
@@ -20,6 +20,7 @@
20 20
21#include "lauxlib.h" 21#include "lauxlib.h"
22#include "lualib.h" 22#include "lualib.h"
23#include "llimits.h"
23 24
24 25
25#undef PI 26#undef PI
@@ -366,25 +367,17 @@ static lua_Number I2d (Rand64 x) {
366 367
367#else /* no 'Rand64' }{ */ 368#else /* no 'Rand64' }{ */
368 369
369/* get an integer with at least 32 bits */
370#if LUAI_IS32INT
371typedef unsigned int lu_int32;
372#else
373typedef unsigned long lu_int32;
374#endif
375
376
377/* 370/*
378** Use two 32-bit integers to represent a 64-bit quantity. 371** Use two 32-bit integers to represent a 64-bit quantity.
379*/ 372*/
380typedef struct Rand64 { 373typedef struct Rand64 {
381 lu_int32 h; /* higher half */ 374 l_uint32 h; /* higher half */
382 lu_int32 l; /* lower half */ 375 l_uint32 l; /* lower half */
383} Rand64; 376} Rand64;
384 377
385 378
386/* 379/*
387** If 'lu_int32' has more than 32 bits, the extra bits do not interfere 380** If 'l_uint32' has more than 32 bits, the extra bits do not interfere
388** with the 32 initial bits, except in a right shift and comparisons. 381** with the 32 initial bits, except in a right shift and comparisons.
389** Moreover, the final result has to discard the extra bits. 382** Moreover, the final result has to discard the extra bits.
390*/ 383*/
@@ -398,7 +391,7 @@ typedef struct Rand64 {
398*/ 391*/
399 392
400/* build a new Rand64 value */ 393/* build a new Rand64 value */
401static Rand64 packI (lu_int32 h, lu_int32 l) { 394static Rand64 packI (l_uint32 h, l_uint32 l) {
402 Rand64 result; 395 Rand64 result;
403 result.h = h; 396 result.h = h;
404 result.l = l; 397 result.l = l;
@@ -471,7 +464,7 @@ static Rand64 nextrand (Rand64 *state) {
471*/ 464*/
472 465
473/* an unsigned 1 with proper type */ 466/* an unsigned 1 with proper type */
474#define UONE ((lu_int32)1) 467#define UONE ((l_uint32)1)
475 468
476 469
477#if FIGS <= 32 470#if FIGS <= 32
@@ -522,7 +515,7 @@ static lua_Unsigned I2UInt (Rand64 x) {
522 515
523/* convert a 'lua_Unsigned' to a 'Rand64' */ 516/* convert a 'lua_Unsigned' to a 'Rand64' */
524static Rand64 Int2I (lua_Unsigned n) { 517static Rand64 Int2I (lua_Unsigned n) {
525 return packI((lu_int32)((n >> 31) >> 1), (lu_int32)n); 518 return packI((l_uint32)((n >> 31) >> 1), (l_uint32)n);
526} 519}
527 520
528#endif /* } */ 521#endif /* } */