Skip to content

Commit 573a60b

Browse files
committed
Fix compilation on MSVC 2022 in release mode
Fixes: #309
1 parent 51608ce commit 573a60b

File tree

1 file changed

+60
-30
lines changed

1 file changed

+60
-30
lines changed

quickjs.c

Lines changed: 60 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -11789,7 +11789,7 @@ int JS_IsArray(JSContext *ctx, JSValue val)
1178911789
}
1179011790
}
1179111791

11792-
static double js_pow(double a, double b)
11792+
static double js_math_pow(double a, double b)
1179311793
{
1179411794
if (unlikely(!isfinite(b)) && fabs(a) == 1) {
1179511795
/* not compatible with IEEE 754 */
@@ -12392,7 +12392,7 @@ static no_inline __exception int js_binary_arith_slow(JSContext *ctx, JSValue *s
1239212392
}
1239312393
break;
1239412394
case OP_pow:
12395-
sp[-2] = js_number(js_pow(v1, v2));
12395+
sp[-2] = js_number(js_math_pow(v1, v2));
1239612396
return 0;
1239712397
default:
1239812398
abort();
@@ -12425,7 +12425,7 @@ static no_inline __exception int js_binary_arith_slow(JSContext *ctx, JSValue *s
1242512425
dr = fmod(d1, d2);
1242612426
break;
1242712427
case OP_pow:
12428-
dr = js_pow(d1, d2);
12428+
dr = js_math_pow(d1, d2);
1242912429
break;
1243012430
default:
1243112431
abort();
@@ -41032,39 +41032,69 @@ static JSValue js_math_random(JSContext *ctx, JSValue this_val,
4103241032
return js_float64(u.d - 1.0);
4103341033
}
4103441034

41035+
/* use local wrappers for math functions to
41036+
- avoid initializing data with dynamic library entry points.
41037+
- avoid some overhead if the call can be inlined at compile or link time.
41038+
*/
41039+
static double js_math_fabs(double d) { return fabs(d); }
41040+
static double js_math_floor(double d) { return floor(d); }
41041+
static double js_math_ceil(double d) { return ceil(d); }
41042+
static double js_math_sqrt(double d) { return sqrt(d); }
41043+
static double js_math_acos(double d) { return acos(d); }
41044+
static double js_math_asin(double d) { return asin(d); }
41045+
static double js_math_atan(double d) { return atan(d); }
41046+
static double js_math_atan2(double a, double b) { return atan2(a, b); }
41047+
static double js_math_cos(double d) { return cos(d); }
41048+
static double js_math_exp(double d) { return exp(d); }
41049+
static double js_math_log(double d) { return log(d); }
41050+
static double js_math_sin(double d) { return sin(d); }
41051+
static double js_math_tan(double d) { return tan(d); }
41052+
static double js_math_trunc(double d) { return trunc(d); }
41053+
static double js_math_cosh(double d) { return cosh(d); }
41054+
static double js_math_sinh(double d) { return sinh(d); }
41055+
static double js_math_tanh(double d) { return tanh(d); }
41056+
static double js_math_acosh(double d) { return acosh(d); }
41057+
static double js_math_asinh(double d) { return asinh(d); }
41058+
static double js_math_atanh(double d) { return atanh(d); }
41059+
static double js_math_expm1(double d) { return expm1(d); }
41060+
static double js_math_log1p(double d) { return log1p(d); }
41061+
static double js_math_log2(double d) { return log2(d); }
41062+
static double js_math_log10(double d) { return log10(d); }
41063+
static double js_math_cbrt(double d) { return cbrt(d); }
41064+
4103541065
static const JSCFunctionListEntry js_math_funcs[] = {
4103641066
JS_CFUNC_MAGIC_DEF("min", 2, js_math_min_max, 0 ),
4103741067
JS_CFUNC_MAGIC_DEF("max", 2, js_math_min_max, 1 ),
41038-
JS_CFUNC_SPECIAL_DEF("abs", 1, f_f, fabs ),
41039-
JS_CFUNC_SPECIAL_DEF("floor", 1, f_f, floor ),
41040-
JS_CFUNC_SPECIAL_DEF("ceil", 1, f_f, ceil ),
41068+
JS_CFUNC_SPECIAL_DEF("abs", 1, f_f, js_math_fabs ),
41069+
JS_CFUNC_SPECIAL_DEF("floor", 1, f_f, js_math_floor ),
41070+
JS_CFUNC_SPECIAL_DEF("ceil", 1, f_f, js_math_ceil ),
4104141071
JS_CFUNC_SPECIAL_DEF("round", 1, f_f, js_math_round ),
41042-
JS_CFUNC_SPECIAL_DEF("sqrt", 1, f_f, sqrt ),
41043-
41044-
JS_CFUNC_SPECIAL_DEF("acos", 1, f_f, acos ),
41045-
JS_CFUNC_SPECIAL_DEF("asin", 1, f_f, asin ),
41046-
JS_CFUNC_SPECIAL_DEF("atan", 1, f_f, atan ),
41047-
JS_CFUNC_SPECIAL_DEF("atan2", 2, f_f_f, atan2 ),
41048-
JS_CFUNC_SPECIAL_DEF("cos", 1, f_f, cos ),
41049-
JS_CFUNC_SPECIAL_DEF("exp", 1, f_f, exp ),
41050-
JS_CFUNC_SPECIAL_DEF("log", 1, f_f, log ),
41051-
JS_CFUNC_SPECIAL_DEF("pow", 2, f_f_f, js_pow ),
41052-
JS_CFUNC_SPECIAL_DEF("sin", 1, f_f, sin ),
41053-
JS_CFUNC_SPECIAL_DEF("tan", 1, f_f, tan ),
41072+
JS_CFUNC_SPECIAL_DEF("sqrt", 1, f_f, js_math_sqrt ),
41073+
41074+
JS_CFUNC_SPECIAL_DEF("acos", 1, f_f, js_math_acos ),
41075+
JS_CFUNC_SPECIAL_DEF("asin", 1, f_f, js_math_asin ),
41076+
JS_CFUNC_SPECIAL_DEF("atan", 1, f_f, js_math_atan ),
41077+
JS_CFUNC_SPECIAL_DEF("atan2", 2, f_f_f, js_math_atan2 ),
41078+
JS_CFUNC_SPECIAL_DEF("cos", 1, f_f, js_math_cos ),
41079+
JS_CFUNC_SPECIAL_DEF("exp", 1, f_f, js_math_exp ),
41080+
JS_CFUNC_SPECIAL_DEF("log", 1, f_f, js_math_log ),
41081+
JS_CFUNC_SPECIAL_DEF("pow", 2, f_f_f, js_math_pow ),
41082+
JS_CFUNC_SPECIAL_DEF("sin", 1, f_f, js_math_sin ),
41083+
JS_CFUNC_SPECIAL_DEF("tan", 1, f_f, js_math_tan ),
4105441084
/* ES6 */
41055-
JS_CFUNC_SPECIAL_DEF("trunc", 1, f_f, trunc ),
41085+
JS_CFUNC_SPECIAL_DEF("trunc", 1, f_f, js_math_trunc ),
4105641086
JS_CFUNC_SPECIAL_DEF("sign", 1, f_f, js_math_sign ),
41057-
JS_CFUNC_SPECIAL_DEF("cosh", 1, f_f, cosh ),
41058-
JS_CFUNC_SPECIAL_DEF("sinh", 1, f_f, sinh ),
41059-
JS_CFUNC_SPECIAL_DEF("tanh", 1, f_f, tanh ),
41060-
JS_CFUNC_SPECIAL_DEF("acosh", 1, f_f, acosh ),
41061-
JS_CFUNC_SPECIAL_DEF("asinh", 1, f_f, asinh ),
41062-
JS_CFUNC_SPECIAL_DEF("atanh", 1, f_f, atanh ),
41063-
JS_CFUNC_SPECIAL_DEF("expm1", 1, f_f, expm1 ),
41064-
JS_CFUNC_SPECIAL_DEF("log1p", 1, f_f, log1p ),
41065-
JS_CFUNC_SPECIAL_DEF("log2", 1, f_f, log2 ),
41066-
JS_CFUNC_SPECIAL_DEF("log10", 1, f_f, log10 ),
41067-
JS_CFUNC_SPECIAL_DEF("cbrt", 1, f_f, cbrt ),
41087+
JS_CFUNC_SPECIAL_DEF("cosh", 1, f_f, js_math_cosh ),
41088+
JS_CFUNC_SPECIAL_DEF("sinh", 1, f_f, js_math_sinh ),
41089+
JS_CFUNC_SPECIAL_DEF("tanh", 1, f_f, js_math_tanh ),
41090+
JS_CFUNC_SPECIAL_DEF("acosh", 1, f_f, js_math_acosh ),
41091+
JS_CFUNC_SPECIAL_DEF("asinh", 1, f_f, js_math_asinh ),
41092+
JS_CFUNC_SPECIAL_DEF("atanh", 1, f_f, js_math_atanh ),
41093+
JS_CFUNC_SPECIAL_DEF("expm1", 1, f_f, js_math_expm1 ),
41094+
JS_CFUNC_SPECIAL_DEF("log1p", 1, f_f, js_math_log1p ),
41095+
JS_CFUNC_SPECIAL_DEF("log2", 1, f_f, js_math_log2 ),
41096+
JS_CFUNC_SPECIAL_DEF("log10", 1, f_f, js_math_log10 ),
41097+
JS_CFUNC_SPECIAL_DEF("cbrt", 1, f_f, js_math_cbrt ),
4106841098
JS_CFUNC_DEF("hypot", 2, js_math_hypot ),
4106941099
JS_CFUNC_DEF("random", 0, js_math_random ),
4107041100
JS_CFUNC_SPECIAL_DEF("fround", 1, f_f, js_math_fround ),

0 commit comments

Comments
 (0)