| 1 |
let values = [-Infinity, Infinity, NaN, 0, -0, -0.1, 0.1, 0.5, -1.6, 1.6, 13.37]; |
| 2 |
|
| 3 |
function unary(name) { |
| 4 |
print(name); |
| 5 |
|
| 6 |
let imports = { |
| 7 |
math: { |
| 8 |
func: Math[name], |
| 9 |
} |
| 10 |
}; |
| 11 |
|
| 12 |
let f32 = x => Math.fround(Math[name](Math.fround(x))); |
| 13 |
let f64 = Math[name]; |
| 14 |
|
| 15 |
let i = wasmEvalText(`(module |
| 16 |
(import "math" "func" (func $f32 (param f32) (result f32))) |
| 17 |
(import "math" "func" (func $f64 (param f64) (result f64))) |
| 18 |
|
| 19 |
(table $t 10 funcref) |
| 20 |
(type $f_f (func (param f32) (result f32))) |
| 21 |
(type $d_d (func (param f64) (result f64))) |
| 22 |
(elem (i32.const 0) $f32 $f64) |
| 23 |
|
| 24 |
(func (export "f32") (param f32) (result f32) |
| 25 |
local.get 0 |
| 26 |
call $f32 |
| 27 |
) |
| 28 |
(func (export "f32_t") (param f32) (result f32) |
| 29 |
local.get 0 |
| 30 |
i32.const 0 |
| 31 |
call_indirect (type $f_f) |
| 32 |
) |
| 33 |
(func (export "f64") (param f64) (result f64) |
| 34 |
local.get 0 |
| 35 |
call $f64 |
| 36 |
) |
| 37 |
(func (export "f64_t") (param f64) (result f64) |
| 38 |
local.get 0 |
| 39 |
i32.const 1 |
| 40 |
call_indirect (type $d_d) |
| 41 |
) |
| 42 |
)`, imports).exports; |
| 43 |
|
| 44 |
for (let v of values) { |
| 45 |
assertEq(i.f32(v), f32(v)); |
| 46 |
assertEq(i.f32_t(v), f32(v)); |
| 47 |
assertEq(i.f64(v), f64(v)); |
| 48 |
assertEq(i.f64_t(v), f64(v)); |
| 49 |
} |
| 50 |
} |
| 51 |
|
| 52 |
function binary(name) { |
| 53 |
print(name); |
| 54 |
|
| 55 |
let imports = { |
| 56 |
math: { |
| 57 |
func: Math[name] |
| 58 |
} |
| 59 |
}; |
| 60 |
|
| 61 |
let f32 = (x, y) => Math.fround(Math[name](Math.fround(x), Math.fround(y))); |
| 62 |
let f64 = Math[name]; |
| 63 |
|
| 64 |
let i = wasmEvalText(`(module |
| 65 |
(import "math" "func" (func $f32 (param f32) (param f32) (result f32))) |
| 66 |
(import "math" "func" (func $f64 (param f64) (param f64) (result f64))) |
| 67 |
|
| 68 |
(table $t 10 funcref) |
| 69 |
(type $ff_f (func (param f32) (param f32) (result f32))) |
| 70 |
(type $dd_d (func (param f64) (param f64) (result f64))) |
| 71 |
(elem (i32.const 0) $f32 $f64) |
| 72 |
|
| 73 |
(func (export "f32") (param f32) (param f32) (result f32) |
| 74 |
local.get 0 |
| 75 |
local.get 1 |
| 76 |
call $f32 |
| 77 |
) |
| 78 |
(func (export "f32_t") (param f32) (param f32) (result f32) |
| 79 |
local.get 0 |
| 80 |
local.get 1 |
| 81 |
i32.const 0 |
| 82 |
call_indirect (type $ff_f) |
| 83 |
) |
| 84 |
(func (export "f64") (param f64) (param f64) (result f64) |
| 85 |
local.get 0 |
| 86 |
local.get 1 |
| 87 |
call $f64 |
| 88 |
) |
| 89 |
(func (export "f64_t") (param f64) (param f64) (result f64) |
| 90 |
local.get 0 |
| 91 |
local.get 1 |
| 92 |
i32.const 1 |
| 93 |
call_indirect (type $dd_d) |
| 94 |
) |
| 95 |
)`, imports).exports; |
| 96 |
|
| 97 |
for (let v of values) { |
| 98 |
for (let w of values) { |
| 99 |
assertEq(i.f32(v, w), f32(v, w)); |
| 100 |
assertEq(i.f64(v, w), f64(v, w)); |
| 101 |
} |
| 102 |
} |
| 103 |
} |
| 104 |
|
| 105 |
unary('sin'); |
| 106 |
unary('sin'); |
| 107 |
unary('tan'); |
| 108 |
unary('cos'); |
| 109 |
unary('exp'); |
| 110 |
unary('log'); |
| 111 |
unary('asin'); |
| 112 |
unary('atan'); |
| 113 |
unary('acos'); |
| 114 |
unary('log10'); |
| 115 |
unary('log2'); |
| 116 |
unary('log1p'); |
| 117 |
unary('expm1'); |
| 118 |
unary('sinh'); |
| 119 |
unary('tanh'); |
| 120 |
unary('cosh'); |
| 121 |
unary('asinh'); |
| 122 |
unary('atanh'); |
| 123 |
unary('acosh'); |
| 124 |
unary('sign'); |
| 125 |
unary('trunc'); |
| 126 |
unary('cbrt'); |
| 127 |
|
| 128 |
binary('atan2'); |
| 129 |
binary('hypot'); |
| 130 |
binary('pow'); |
| 131 |
|
| 132 |
print('done'); |