Fix js_math_imul
(#356)
- follow ECMA specification - remove implementation defined signed conversion
This commit is contained in:
parent
97c918662b
commit
0658d9c3e9
1 changed files with 7 additions and 7 deletions
14
quickjs.c
14
quickjs.c
|
@ -40943,16 +40943,16 @@ static double js_math_fround(double a)
|
||||||
static JSValue js_math_imul(JSContext *ctx, JSValue this_val,
|
static JSValue js_math_imul(JSContext *ctx, JSValue this_val,
|
||||||
int argc, JSValue *argv)
|
int argc, JSValue *argv)
|
||||||
{
|
{
|
||||||
int a, b;
|
uint32_t a, b, c;
|
||||||
|
int32_t d;
|
||||||
|
|
||||||
if (JS_ToInt32(ctx, &a, argv[0]))
|
if (JS_ToUint32(ctx, &a, argv[0]))
|
||||||
return JS_EXCEPTION;
|
return JS_EXCEPTION;
|
||||||
if (JS_ToInt32(ctx, &b, argv[1]))
|
if (JS_ToUint32(ctx, &b, argv[1]))
|
||||||
return JS_EXCEPTION;
|
return JS_EXCEPTION;
|
||||||
/* TODO(bnoordhuis) Signed integral narrowing has implementation-defined
|
c = a * b;
|
||||||
* behavior but that's a step up from the undefined behavior it replaced.
|
memcpy(&d, &c, sizeof(d));
|
||||||
*/
|
return js_int32(d);
|
||||||
return js_int32((int64_t)a * (int64_t)b);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static JSValue js_math_clz32(JSContext *ctx, JSValue this_val,
|
static JSValue js_math_clz32(JSContext *ctx, JSValue this_val,
|
||||||
|
|
Loading…
Reference in a new issue