mirror of
https://github.com/fluencelabs/assemblyscript
synced 2025-06-18 01:11:32 +00:00
Fix Math.imul and add tests (#432)
This commit is contained in:
@ -550,7 +550,18 @@ export namespace NativeMath {
|
||||
}
|
||||
|
||||
export function imul(x: f64, y: f64): f64 {
|
||||
return <f64>(<i32>x * <i32>y);
|
||||
/*
|
||||
* Wasm (MVP) and JS have different approachas for double->int conversions.
|
||||
*
|
||||
* For emulate JS conversion behavior and avoid trapping from wasm we should modulate by MAX_INT
|
||||
* our float-point arguments before actual convertion to integers.
|
||||
*/
|
||||
if (!isFinite(x + y)) return 0;
|
||||
const inv32 = 1.0 / 4294967296;
|
||||
return (
|
||||
<i32><i64>(x - 4294967296 * builtin_floor(x * inv32)) *
|
||||
<i32><i64>(y - 4294967296 * builtin_floor(y * inv32))
|
||||
);
|
||||
}
|
||||
|
||||
export function log(x: f64): f64 { // see: musl/src/math/log.c and SUN COPYRIGHT NOTICE above
|
||||
|
Reference in New Issue
Block a user