diff options
author | Mike Pall <mike> | 2009-12-08 19:49:20 +0100 |
---|---|---|
committer | Mike Pall <mike> | 2009-12-08 19:49:20 +0100 |
commit | 1d1fed48a002dfc0919135911057ebc255a53e0a (patch) | |
tree | c5c6643908374bb8f02f4c7691332d32f6645986 /src/lib_math.c | |
parent | 55b16959717084884fd4a0cbae6d19e3786c20c7 (diff) | |
download | luajit-1d1fed48a002dfc0919135911057ebc255a53e0a.tar.gz luajit-1d1fed48a002dfc0919135911057ebc255a53e0a.tar.bz2 luajit-1d1fed48a002dfc0919135911057ebc255a53e0a.zip |
RELEASE LuaJIT-2.0.0-beta2v2.0.0-beta2
Diffstat (limited to 'src/lib_math.c')
-rw-r--r-- | src/lib_math.c | 19 |
1 files changed, 4 insertions, 15 deletions
diff --git a/src/lib_math.c b/src/lib_math.c index ec8b0c2b..adc77c9d 100644 --- a/src/lib_math.c +++ b/src/lib_math.c | |||
@@ -69,11 +69,9 @@ LJLIB_ASM_(math_max) LJLIB_REC(math_minmax IR_MAX) | |||
69 | LJLIB_PUSH(3.14159265358979323846) LJLIB_SET(pi) | 69 | LJLIB_PUSH(3.14159265358979323846) LJLIB_SET(pi) |
70 | LJLIB_PUSH(1e310) LJLIB_SET(huge) | 70 | LJLIB_PUSH(1e310) LJLIB_SET(huge) |
71 | 71 | ||
72 | #ifdef __MACH__ | ||
73 | LJ_FUNCA double lj_wrapper_sinh(double x) { return sinh(x); } | 72 | LJ_FUNCA double lj_wrapper_sinh(double x) { return sinh(x); } |
74 | LJ_FUNCA double lj_wrapper_cosh(double x) { return cosh(x); } | 73 | LJ_FUNCA double lj_wrapper_cosh(double x) { return cosh(x); } |
75 | LJ_FUNCA double lj_wrapper_tanh(double x) { return tanh(x); } | 74 | LJ_FUNCA double lj_wrapper_tanh(double x) { return tanh(x); } |
76 | #endif | ||
77 | 75 | ||
78 | /* ------------------------------------------------------------------------ */ | 76 | /* ------------------------------------------------------------------------ */ |
79 | 77 | ||
@@ -98,8 +96,8 @@ typedef union { uint64_t u64; double d; } U64double; | |||
98 | z = (((z<<q)^z) >> (k-s)) ^ ((z&((uint64_t)(int64_t)-1 << (64-k)))<<s); \ | 96 | z = (((z<<q)^z) >> (k-s)) ^ ((z&((uint64_t)(int64_t)-1 << (64-k)))<<s); \ |
99 | r ^= z; tw->gen[i] = z; | 97 | r ^= z; tw->gen[i] = z; |
100 | 98 | ||
101 | /* PRNG step function. Returns a double in the range 0.0 <= d < 1.0. */ | 99 | /* PRNG step function. Returns a double in the range 1.0 <= d < 2.0. */ |
102 | static double tw223_step(TW223State *tw) | 100 | static LJ_NOINLINE double tw223_step(TW223State *tw) |
103 | { | 101 | { |
104 | uint64_t z, r = 0; | 102 | uint64_t z, r = 0; |
105 | U64double u; | 103 | U64double u; |
@@ -108,16 +106,7 @@ static double tw223_step(TW223State *tw) | |||
108 | TW223_GEN(2, 55, 24, 7) | 106 | TW223_GEN(2, 55, 24, 7) |
109 | TW223_GEN(3, 47, 21, 8) | 107 | TW223_GEN(3, 47, 21, 8) |
110 | u.u64 = (r & (((uint64_t)1 << 52)-1)) | ((uint64_t)0x3ff << 52); | 108 | u.u64 = (r & (((uint64_t)1 << 52)-1)) | ((uint64_t)0x3ff << 52); |
111 | #if defined(__GNUC__) && LJ_TARGET_X86 && __pic__ | 109 | return u.d; |
112 | /* Compensate for unbelievable GCC pessimization. */ | ||
113 | { | ||
114 | volatile U64double u1; | ||
115 | u1.u64 = (uint64_t)0x3f8 << 52; | ||
116 | return u.d - u1.d; | ||
117 | } | ||
118 | #else | ||
119 | return u.d - 1.0; | ||
120 | #endif | ||
121 | } | 110 | } |
122 | 111 | ||
123 | /* PRNG initialization function. */ | 112 | /* PRNG initialization function. */ |
@@ -146,7 +135,7 @@ LJLIB_CF(math_random) | |||
146 | TW223State *tw = (TW223State *)(uddata(udataV(lj_lib_upvalue(L, 1)))); | 135 | TW223State *tw = (TW223State *)(uddata(udataV(lj_lib_upvalue(L, 1)))); |
147 | double d; | 136 | double d; |
148 | if (LJ_UNLIKELY(!tw->valid)) tw223_init(tw, 0.0); | 137 | if (LJ_UNLIKELY(!tw->valid)) tw223_init(tw, 0.0); |
149 | d = tw223_step(tw); | 138 | d = tw223_step(tw) - 1.0; |
150 | if (n > 0) { | 139 | if (n > 0) { |
151 | double r1 = lj_lib_checknum(L, 1); | 140 | double r1 = lj_lib_checknum(L, 1); |
152 | if (n == 1) { | 141 | if (n == 1) { |