mirror of
https://github.com/fluencelabs/assemblyscript
synced 2025-04-25 07:02:13 +00:00
Implement Math/Mathf.pow
This commit is contained in:
parent
e26734ef90
commit
e75d006d26
@ -765,10 +765,16 @@ function measure(fn) {
|
||||
|
||||
exports.measure = measure;
|
||||
|
||||
function formatTime(time) {
|
||||
return time ? (time / 1e6).toFixed(3) + " ms" : "N/A";
|
||||
}
|
||||
|
||||
exports.formatTime = formatTime;
|
||||
|
||||
/** Formats and prints out the contents of a set of stats. */
|
||||
function printStats(stats, output) {
|
||||
function format(time, count) {
|
||||
return time ? (time / 1e6).toFixed(3) + " ms" : "N/A";
|
||||
return formatTime(time);
|
||||
}
|
||||
(output || process.stdout).write([
|
||||
"I/O Read : " + format(stats.readTime, stats.readCount),
|
||||
|
2
dist/asc.js
vendored
2
dist/asc.js
vendored
File diff suppressed because one or more lines are too long
2
dist/asc.js.map
vendored
2
dist/asc.js.map
vendored
File diff suppressed because one or more lines are too long
2
dist/assemblyscript.js
vendored
2
dist/assemblyscript.js
vendored
File diff suppressed because one or more lines are too long
2
dist/assemblyscript.js.map
vendored
2
dist/assemblyscript.js.map
vendored
File diff suppressed because one or more lines are too long
@ -5,19 +5,19 @@
|
||||
label { cursor: pointer; }
|
||||
</style>
|
||||
|
||||
<script src="hexfloat.js"></script>
|
||||
<form onsubmit="convert(this); return false">
|
||||
<h1>Hexadecimal float to decimal float converter</h1>
|
||||
<p>
|
||||
<label for="f64"><input id="f64" name="precision" value="f64" type="radio" checked /> f64</label>
|
||||
<label for="f32"><input id="f32" name="precision" value="f32" type="radio" /> f32</label>
|
||||
<input id="name" type="text" value="test(" />
|
||||
<input id="name" type="text" value="test" />
|
||||
<button>Convert</button>
|
||||
</p>
|
||||
<p><textarea cols="120" rows="20" id="input"></textarea></p>
|
||||
<p><textarea cols="120" rows="20" id="output" readonly></textarea></p>
|
||||
</form>
|
||||
|
||||
<script src="hexfloat.js"></script>
|
||||
<script>
|
||||
function convert(form) {
|
||||
var isF64 = document.getElementById("f64").checked;
|
||||
@ -29,8 +29,8 @@ function convert(form) {
|
||||
return val.toPrecision(isF64 ? 18 : 10);
|
||||
})
|
||||
.replace(/\bnan\b/g, "NaN")
|
||||
.replace(/\inf\b/g, "Infinity")
|
||||
.replace(/^T\(RN, */mg, name + "(")
|
||||
.replace(/\binf\b/g, "Infinity")
|
||||
.replace(/^T\(R\w, */mg, name + "(")
|
||||
.replace(/\)$/mg, ");")
|
||||
.replace(/ +/g, " ");
|
||||
}
|
||||
|
@ -1903,7 +1903,7 @@ export function compileCall(
|
||||
}
|
||||
let type = compiler.currentType;
|
||||
arg1 = compiler.compileExpression(operands[1], type);
|
||||
arg2 = compiler.compileExpression(operands[2], Type.bool);
|
||||
arg2 = compiler.compileExpression(operands[2], Type.i32);
|
||||
compiler.currentType = type;
|
||||
switch (compiler.currentType.kind) {
|
||||
default: { // any value type
|
||||
|
@ -4904,24 +4904,21 @@ export class Compiler extends DiagnosticEmitter {
|
||||
if (i64_is_i8(intValue)) return module.createI32(i64_low(intValue));
|
||||
break;
|
||||
}
|
||||
case TypeKind.I16: {
|
||||
if (i64_is_i16(intValue)) return module.createI32(i64_low(intValue));
|
||||
break;
|
||||
}
|
||||
case TypeKind.I32: {
|
||||
if (i64_is_i32(intValue)) return module.createI32(i64_low(intValue));
|
||||
break;
|
||||
}
|
||||
case TypeKind.U8: {
|
||||
if (i64_is_u8(intValue)) return module.createI32(i64_low(intValue));
|
||||
break;
|
||||
}
|
||||
case TypeKind.I16: {
|
||||
if (i64_is_i16(intValue)) return module.createI32(i64_low(intValue));
|
||||
break;
|
||||
}
|
||||
case TypeKind.U16: {
|
||||
if (i64_is_u16(intValue)) return module.createI32(i64_low(intValue));
|
||||
break;
|
||||
}
|
||||
case TypeKind.I32:
|
||||
case TypeKind.U32: {
|
||||
if (i64_is_u32(intValue)) return module.createI32(i64_low(intValue));
|
||||
if (i64_is_i32(intValue) || i64_is_u32(intValue)) return module.createI32(i64_low(intValue));
|
||||
break;
|
||||
}
|
||||
case TypeKind.BOOL: {
|
||||
@ -4930,14 +4927,14 @@ export class Compiler extends DiagnosticEmitter {
|
||||
}
|
||||
case TypeKind.ISIZE: {
|
||||
if (!this.options.isWasm64) {
|
||||
if (i64_is_u32(intValue)) return module.createI32(i64_low(intValue));
|
||||
if (i64_is_i32(intValue) || i64_is_u32(intValue)) return module.createI32(i64_low(intValue));
|
||||
break;
|
||||
}
|
||||
return module.createI64(i64_low(intValue), i64_high(intValue));
|
||||
}
|
||||
case TypeKind.USIZE: {
|
||||
if (!this.options.isWasm64) {
|
||||
if (i64_is_u32(intValue)) return module.createI32(i64_low(intValue));
|
||||
if (i64_is_i32(intValue) || i64_is_u32(intValue)) return module.createI32(i64_low(intValue));
|
||||
break;
|
||||
}
|
||||
return module.createI64(i64_low(intValue), i64_high(intValue));
|
||||
|
2
std/assembly.d.ts
vendored
2
std/assembly.d.ts
vendored
@ -418,6 +418,7 @@ declare namespace Math {
|
||||
export function log(x: f64): f64;
|
||||
export function max(value1: f64, value2: f64): f64; // TODO: see std/math
|
||||
export function min(value1: f64, value2: f64): f64; // TODO: see std/math
|
||||
export function pow(x: f64, y: f64): f64;
|
||||
export function round(x: f64): f64;
|
||||
export function sign(x: f64): f64;
|
||||
export function sqrt(x: f64): f64;
|
||||
@ -442,6 +443,7 @@ declare namespace Mathf {
|
||||
export function log(x: f32): f32;
|
||||
export function max(value1: f32, value2: f32): f32; // TODO: see std/math
|
||||
export function min(value1: f32, value2: f32): f32; // TODO: see std/math
|
||||
export function pow(x: f32, y: f32): f32;
|
||||
export function round(x: f32): f32;
|
||||
export function sign(x: f32): f32;
|
||||
export function sqrt(x: f32): f32;
|
||||
|
@ -58,7 +58,7 @@ import {
|
||||
trunc as builtin_trunc
|
||||
} from "./builtins";
|
||||
|
||||
// Math/Mathf.log/exp
|
||||
// Math/Mathf.log/exp/pow
|
||||
// Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
|
||||
// Developed at SunPro, a Sun Microsystems, Inc. business.
|
||||
// Permission to use, copy, modify, and distribute this
|
||||
@ -88,10 +88,8 @@ export namespace Math {
|
||||
return builtin_clz(<i32>x);
|
||||
}
|
||||
|
||||
export function exp(x: f64): f64 {
|
||||
// based on musl's implementation of exp:
|
||||
export function exp(x: f64): f64 { // based on musl's implementation of exp
|
||||
const
|
||||
half = <f64[]>[0.5,-0.5],
|
||||
ln2hi = 6.93147180369123816490e-01, // 0x3fe62e42, 0xfee00000
|
||||
ln2lo = 1.90821492927058770002e-10, // 0x3dea39ef, 0x35793c76
|
||||
invln2 = 1.44269504088896338700e+00, // 0x3ff71547, 0x652b82fe
|
||||
@ -103,7 +101,6 @@ export namespace Math {
|
||||
Ox1p1023 = 8.98846567431157954e+307;
|
||||
|
||||
var hx = <u32>(reinterpret<u64>(x) >> 32);
|
||||
var sign_ = hx >> 31;
|
||||
hx &= 0x7fffffff; // high word of |x|
|
||||
|
||||
// special cases
|
||||
@ -125,8 +122,9 @@ export namespace Math {
|
||||
var k: i32;
|
||||
if (hx > 0x3fd62e42) { // if |x| > 0.5 ln2
|
||||
if (hx >= 0x3ff0a2b2) { // if |x| >= 1.5 ln2
|
||||
k = <i32>(invln2 * x + half[sign_]);
|
||||
k = <i32>(invln2 * x + copysign<f64>(0.5, x)); // was: [0.5, -0.5][sign_])
|
||||
} else {
|
||||
let sign_ = hx >> 31;
|
||||
k = 1 - sign_ - sign_;
|
||||
}
|
||||
hi = x - k * ln2hi; // k * ln2hi is exact here
|
||||
@ -223,6 +221,236 @@ export namespace Math {
|
||||
return builtin_min(value1, value2);
|
||||
}
|
||||
|
||||
export function pow(x: f64, y: f64): f64 { // pased on musl's implementation of pow
|
||||
const
|
||||
two53 = 9007199254740992.0, // 0x43400000, 0x00000000
|
||||
huge = 1.0e+300,
|
||||
tiny = 1.0e-300,
|
||||
// poly coefs for (3/2)*(log(x)-2s-2/3*s**3
|
||||
L1 = 5.99999999999994648725e-01, // 0x3FE33333, 0x33333303
|
||||
L2 = 4.28571428578550184252e-01, // 0x3FDB6DB6, 0xDB6FABFF
|
||||
L3 = 3.33333329818377432918e-01, // 0x3FD55555, 0x518F264D
|
||||
L4 = 2.72728123808534006489e-01, // 0x3FD17460, 0xA91D4101
|
||||
L5 = 2.30660745775561754067e-01, // 0x3FCD864A, 0x93C9DB65
|
||||
L6 = 2.06975017800338417784e-01, // 0x3FCA7E28, 0x4A454EEF
|
||||
P1 = 1.66666666666666019037e-01, // 0x3FC55555, 0x5555553E
|
||||
P2 = -2.77777777770155933842e-03, // 0xBF66C16C, 0x16BEBD93
|
||||
P3 = 6.61375632143793436117e-05, // 0x3F11566A, 0xAF25DE2C
|
||||
P4 = -1.65339022054652515390e-06, // 0xBEBBBD41, 0xC5D26BF1
|
||||
P5 = 4.13813679705723846039e-08, // 0x3E663769, 0x72BEA4D0
|
||||
lg2 = 6.93147180559945286227e-01, // 0x3FE62E42, 0xFEFA39EF
|
||||
lg2_h = 6.93147182464599609375e-01, // 0x3FE62E43, 0x00000000
|
||||
lg2_l = -1.90465429995776804525e-09, // 0xBE205C61, 0x0CA86C39
|
||||
ovt = 8.0085662595372944372e-017, // -(1024-log2(ovfl+.5ulp))
|
||||
cp = 9.61796693925975554329e-01, // 0x3FEEC709, 0xDC3A03FD =2/(3ln2)
|
||||
cp_h = 9.61796700954437255859e-01, // 0x3FEEC709, 0xE0000000 =(float)cp
|
||||
cp_l = -7.02846165095275826516e-09, // 0xBE3E2FE0, 0x145B01F5 =tail of cp_h
|
||||
ivln2 = 1.44269504088896338700e+00, // 0x3FF71547, 0x652B82FE =1/ln2
|
||||
ivln2_h = 1.44269502162933349609e+00, // 0x3FF71547, 0x60000000 =24b 1/ln2
|
||||
ivln2_l = 1.92596299112661746887e-0; // 0x3E54AE0B, 0xF85DDF44 =1/ln2 tail
|
||||
|
||||
var __u = reinterpret<u64>(x); // EXTRACT_WORDS(hx, lx, x)
|
||||
var hx = <i32>(__u >> 32);
|
||||
var lx = <u32>__u;
|
||||
|
||||
__u = reinterpret<u64>(y); // EXTRACT_WORDS(hy, ly, y)
|
||||
var hy = <i32>(__u >> 32);
|
||||
var ly = <u32>__u;
|
||||
|
||||
var ix = hx & 0x7fffffff;
|
||||
var iy = hy & 0x7fffffff;
|
||||
|
||||
// x**0 = 1, even if x is NaN
|
||||
if ((iy | ly) == 0) return 1.0;
|
||||
// 1**y = 1, even if y is NaN
|
||||
if (hx == 0x3ff00000 && lx == 0) return 1.0;
|
||||
// NaN if either arg is NaN
|
||||
if (
|
||||
ix > 0x7ff00000 || (ix == 0x7ff00000 && lx != 0) ||
|
||||
iy > 0x7ff00000 || (iy == 0x7ff00000 && ly != 0)
|
||||
) return x + y;
|
||||
|
||||
// determine if y is an odd int when x < 0
|
||||
// yisint = 0 ... y is not an integer
|
||||
// yisint = 1 ... y is an odd int
|
||||
// yisint = 2 ... y is an even int
|
||||
var yisint = 0, k: i32;
|
||||
if (hx < 0) {
|
||||
if (iy >= 0x43400000) yisint = 2; // even integer y
|
||||
else if (iy >= 0x3ff00000) {
|
||||
k = (iy >> 20) - 0x3ff; // exponent
|
||||
if (k > 20) {
|
||||
let jj = ly >> (52 - k);
|
||||
if ((jj << (52 - k)) == ly) yisint = 2 - (jj & 1);
|
||||
} else if (ly == 0) {
|
||||
let jj = iy >> (20 - k);
|
||||
if ((jj << (20 - k)) == iy) yisint = 2 - (jj & 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// special value of y
|
||||
if (ly == 0) {
|
||||
if (iy == 0x7ff00000) { // y is +-inf
|
||||
if (((ix - 0x3ff00000) | lx) == 0) return 1.0; // (-1)**+-inf is 1
|
||||
else if (ix >= 0x3ff00000) return hy >= 0 ? y : 0.0; // (|x|>1)**+-inf = inf,0
|
||||
else return hy >= 0 ? 0.0 : -y; // (|x|<1)**+-inf = 0,inf
|
||||
}
|
||||
if (iy == 0x3ff00000) { // y is +-1
|
||||
if (hy >= 0) return x;
|
||||
return 1 / x;
|
||||
}
|
||||
if (hy == 0x40000000) return x * x; // y is 2
|
||||
if (hy == 0x3fe00000) { // y is 0.5
|
||||
if (hx >= 0) return sqrt(x); // x >= +0
|
||||
}
|
||||
}
|
||||
|
||||
var ax = builtin_abs(x), z: f64;
|
||||
// special value of x
|
||||
if (lx == 0) {
|
||||
if (ix == 0x7ff00000 || ix == 0 || ix == 0x3ff00000) { // x is +-0,+-inf,+-1
|
||||
z = ax;
|
||||
if (hy < 0) z = 1.0 / z; // z = (1/|x|)
|
||||
if (hx < 0) {
|
||||
if (((ix - 0x3ff00000) | yisint) == 0) z = (z - z) / (z - z); // (-1)**non-int is NaN
|
||||
else if (yisint == 1) z = -z; // (x<0)**odd = -(|x|**odd)
|
||||
}
|
||||
return z;
|
||||
}
|
||||
}
|
||||
|
||||
var s = 1.0; // sign of result
|
||||
if (hx < 0) {
|
||||
if (yisint == 0) return (x - x) / (x - x); // (x<0)**(non-int) is NaN
|
||||
if (yisint == 1) s = -1.0; // (x<0)**(odd int)
|
||||
}
|
||||
|
||||
// |y| is huge
|
||||
var t1: f64, t2: f64, p_h: f64, p_l: f64, r: f64, t: f64, u: f64, v: f64, w: f64;
|
||||
var j: i32, n: i32;
|
||||
if (iy > 0x41e00000) { // if |y| > 2**31
|
||||
if (iy > 0x43f00000) { // if |y| > 2**64, must o/uflow
|
||||
if (ix <= 0x3fefffff) return hy < 0 ? huge * huge : tiny * tiny;
|
||||
if (ix >= 0x3ff00000) return hy > 0 ? huge * huge : tiny * tiny;
|
||||
}
|
||||
// over/underflow if x is not close to one
|
||||
if (ix < 0x3fefffff) return hy < 0 ? s * huge * huge : s * tiny * tiny;
|
||||
if (ix > 0x3ff00000) return hy > 0 ? s * huge * huge : s * tiny * tiny;
|
||||
// now |1-x| is tiny <= 2**-20, suffice to compute
|
||||
// log(x) by x-x^2/2+x^3/3-x^4/4
|
||||
t = ax - 1.0; // t has 20 trailing zeros
|
||||
w = (t * t) * (0.5 - t * (0.3333333333333333333333 - t * 0.25));
|
||||
u = ivln2_h * t; // ivln2_h has 21 sig. bits
|
||||
v = t * ivln2_l - w * ivln2;
|
||||
t1 = u + v;
|
||||
t1 = reinterpret<f64>(reinterpret<u64>(t1) & 0xffffffff00000000); // SET_LOW_WORD(t1, 0)
|
||||
t2 = v - (t1 - u);
|
||||
} else {
|
||||
let ss: f64, s2: f64, s_h: f64, s_l: f64, t_h: f64, t_l: f64;
|
||||
n = 0;
|
||||
// take care subnormal number
|
||||
if (ix < 0x00100000) {
|
||||
ax *= two53;
|
||||
n -= 53;
|
||||
ix = <u32>(reinterpret<u64>(ax) >> 32);
|
||||
}
|
||||
n += (ix >> 20) - 0x3ff;
|
||||
j = ix & 0x000fffff;
|
||||
// determine interval
|
||||
ix = j | 0x3ff00000; // normalize ix
|
||||
if (j <= 0x3988E) k = 0; // |x|<sqrt(3/2)
|
||||
else if (j < 0xBB67A) k = 1; // |x|<sqrt(3)
|
||||
else {
|
||||
k = 0;
|
||||
n += 1;
|
||||
ix -= 0x00100000;
|
||||
}
|
||||
ax = reinterpret<f64>(reinterpret<u64>(ax) & 0xffffffff | (<u64>ix << 32)); // SET_HIGH_WORD(ax, ix)
|
||||
|
||||
// compute ss = s_h+s_l = (x-1)/(x+1) or (x-1.5)/(x+1.5)
|
||||
let bp = select<f64>(1.5, 1.0, k); // bp[k], bp[0]=1.0, bp[1]=1.5
|
||||
u = ax - bp;
|
||||
v = 1.0 / (ax + bp);
|
||||
ss = u * v;
|
||||
s_h = ss;
|
||||
s_h = reinterpret<f64>(reinterpret<u64>(s_h) & 0xffffffff00000000); // SET_LOW_WORD(s_h, 0)
|
||||
// t_h=ax+bp[k] High
|
||||
t_h = reinterpret<f64>(<u64>(((ix >> 1) | 0x20000000) + 0x00080000 + (k << 18)) << 32); // SET_HIGH_WORD
|
||||
t_l = ax - (t_h - bp);
|
||||
s_l = v * ((u - s_h * t_h) - s_h * t_l);
|
||||
// compute log(ax)
|
||||
s2 = ss * ss;
|
||||
r = s2 * s2 * (L1 + s2 * (L2 + s2 * (L3 + s2 * (L4 + s2 * (L5 + s2 * L6)))));
|
||||
r += s_l * (s_h + ss);
|
||||
s2 = s_h * s_h;
|
||||
t_h = 3.0 + s2 + r;
|
||||
t_h = reinterpret<f64>(reinterpret<u64>(t_h) & 0xffffffff00000000); // SET_LOW_WORD(t_h, 0)
|
||||
t_l = r - ((t_h - 3.0) - s2);
|
||||
// u+v = ss*(1+...)
|
||||
u = s_h * t_h;
|
||||
v = s_l * t_h + t_l * ss;
|
||||
// 2/(3log2)*(ss+...)
|
||||
p_h = u + v;
|
||||
p_h = reinterpret<f64>(reinterpret<u64>(p_h) & 0xffffffff00000000); // SET_LOW_WORD(p_h, 0)
|
||||
p_l = v - (p_h - u);
|
||||
let z_h = cp_h * p_h; // cp_h+cp_l = 2/(3*log2)
|
||||
let dp_l = select<f64>(1.35003920212974897128e-08, 0.0, k); // dp_l[k]
|
||||
let z_l = cp_l * p_h + p_l * cp + dp_l;
|
||||
// log2(ax) = (ss+..)*2/(3*log2) = n + dp_h + z_h + z_l
|
||||
t = <f64>n;
|
||||
let dp_h = select<f64>(5.84962487220764160156e-01, 0.0, k); // dp_h[k]
|
||||
t1 = ((z_h + z_l) + dp_h) + t;
|
||||
t1 = reinterpret<f64>(reinterpret<u64>(t1) & 0xffffffff00000000); // SET_LOW_WORD(t1, 0);
|
||||
t2 = z_l - (((t1 - t) - dp_h) - z_h);
|
||||
}
|
||||
|
||||
// split up y into y1+y2 and compute (y1+y2)*(t1+t2)
|
||||
var y1 = y;
|
||||
y1 = reinterpret<f64>(reinterpret<u64>(y1) & 0xffffffff00000000); // SET_LOW_WORD(y1, 0)
|
||||
p_l = (y - y1) * t1 + y * t2;
|
||||
p_h = y1 * t1;
|
||||
z = p_l + p_h;
|
||||
__u = reinterpret<u64>(z); // EXTRACT_WORDS(j, i, z) ...
|
||||
j = <u32>(__u >> 32);
|
||||
var i = <i32>__u;
|
||||
if (j >= 0x40900000) { // z >= 1024
|
||||
if (((j - 0x40900000) | i) != 0) return s * huge * huge; // if z > 1024, overflow
|
||||
if (p_l + ovt > z - p_h) return s * huge * huge; // overflow
|
||||
} else if ((j & 0x7fffffff) >= 0x4090cc00) { // z <= -1075, FIXME: instead of abs(j) use unsigned j
|
||||
if (((j - 0xc090cc00) | i) != 0) return s * tiny * tiny; // z < -1075, underflow
|
||||
if (p_l <= z - p_h) return s * tiny * tiny; // underflow
|
||||
}
|
||||
// compute 2**(p_h+p_l)
|
||||
i = j & 0x7fffffff;
|
||||
k = (i >> 20) - 0x3ff;
|
||||
n = 0;
|
||||
if (i > 0x3fe00000) { // if |z| > 0.5, set n = [z+0.5]
|
||||
n = j + (0x00100000 >> (k + 1));
|
||||
k = ((n & 0x7fffffff) >> 20) - 0x3ff; // new k for n
|
||||
t = 0.0;
|
||||
t = reinterpret<f64>(<u64>(n & ~(0x000fffff >> k)) << 32); // SET_HIGH_WORD(t, n & ~(0x000fffff>>k))
|
||||
n = ((n & 0x000fffff) | 0x00100000) >> (20 - k);
|
||||
if (j < 0) n = -n;
|
||||
p_h -= t;
|
||||
}
|
||||
t = p_l + p_h;
|
||||
t = reinterpret<f64>(reinterpret<u64>(t) & 0xffffffff00000000); // SET_LOW_WORD(t, 0)
|
||||
u = t * lg2_h;
|
||||
v = (p_l - (t - p_h)) * lg2 + t * lg2_l;
|
||||
z = u + v;
|
||||
w = v - (z - u);
|
||||
t = z * z;
|
||||
t1 = z - t * (P1 + t * (P2 + t * (P3 + t * (P4 + t * P5))));
|
||||
r = (z * t1) / (t1 - 2.0) - (w + z * w);
|
||||
z = 1.0 - (r - z);
|
||||
j = <u32>(reinterpret<u64>(z) >> 32); // GET_HIGH_WORD(j, z)
|
||||
j += n << 20;
|
||||
if ((j >> 20) <= 0) z = scalbn(z, n); // subnormal output
|
||||
else z = reinterpret<f64>(reinterpret<u64>(z) & 0xffffffff | (<u64>j << 32)); // SET_HIGH_WORD(z, j)
|
||||
return s * z;
|
||||
}
|
||||
|
||||
export function round(x: f64): f64 {
|
||||
return builtin_nearest(x);
|
||||
}
|
||||
@ -269,7 +497,6 @@ export namespace Mathf {
|
||||
|
||||
export function exp(x: f32): f32 { // based on musl's implementation of expf
|
||||
const
|
||||
half = <f32[]>[0.5,-0.5],
|
||||
ln2hi = <f32>6.9314575195e-1, // 0x3f317200
|
||||
ln2lo = <f32>1.4286067653e-6, // 0x35bfbe8e
|
||||
invln2 = <f32>1.4426950216e+0, // 0x3fb8aa3b
|
||||
@ -292,7 +519,7 @@ export namespace Mathf {
|
||||
}
|
||||
if (sign_) {
|
||||
// underflow
|
||||
if (hx >= 0x42cff1b5) { // x <= -103.972084f */
|
||||
if (hx >= 0x42cff1b5) { // x <= -103.972084f
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
@ -303,7 +530,7 @@ export namespace Mathf {
|
||||
var k: i32;
|
||||
if (hx > 0x3eb17218) { // if |x| > 0.5 ln2
|
||||
if (hx > 0x3f851592) { // if |x| > 1.5 ln2
|
||||
k = <i32>(invln2 * x + half[sign_]);
|
||||
k = <i32>(invln2 * x + copysign<f32>(0.5, x)); // was: [0.5, -0.5][sign_])
|
||||
} else {
|
||||
k = 1 - sign_ - sign_;
|
||||
}
|
||||
@ -387,6 +614,219 @@ export namespace Mathf {
|
||||
return builtin_min(value1, value2);
|
||||
}
|
||||
|
||||
export function pow(x: f32, y: f32): f32 { // based on musl's implementation of powf
|
||||
const
|
||||
two24 = <f32>16777216.0, // 0x4b800000
|
||||
huge = <f32>1.0e30,
|
||||
tiny = <f32>1.0e-30,
|
||||
// poly coefs for (3/2)*(log(x)-2s-2/3*s**3
|
||||
L1 = <f32>6.0000002384e-01, // 0x3f19999a
|
||||
L2 = <f32>4.2857143283e-01, // 0x3edb6db7
|
||||
L3 = <f32>3.3333334327e-01, // 0x3eaaaaab
|
||||
L4 = <f32>2.7272811532e-01, // 0x3e8ba305
|
||||
L5 = <f32>2.3066075146e-01, // 0x3e6c3255
|
||||
L6 = <f32>2.0697501302e-01, // 0x3e53f142
|
||||
P1 = <f32>1.6666667163e-01, // 0x3e2aaaab
|
||||
P2 = <f32>-2.7777778450e-03, // 0xbb360b61
|
||||
P3 = <f32>6.6137559770e-05, // 0x388ab355
|
||||
P4 = <f32>-1.6533901999e-06, // 0xb5ddea0e
|
||||
P5 = <f32>4.1381369442e-08, // 0x3331bb4c
|
||||
lg2 = <f32>6.9314718246e-01, // 0x3f317218
|
||||
lg2_h = <f32>6.93145752e-01, // 0x3f317200
|
||||
lg2_l = <f32>1.42860654e-06, // 0x35bfbe8c
|
||||
ovt = <f32>4.2995665694e-08, // -(128-log2(ovfl+.5ulp))
|
||||
cp = <f32>9.6179670095e-01, // 0x3f76384f =2/(3ln2)
|
||||
cp_h = <f32>9.6191406250e-01, // 0x3f764000 =12b cp
|
||||
cp_l = <f32>-1.1736857402e-04, // 0xb8f623c6 =tail of cp_h
|
||||
ivln2 = <f32>1.4426950216e+00, // 0x3fb8aa3b =1/ln2
|
||||
ivln2_h = <f32>1.4426879883e+00, // 0x3fb8aa00 =16b 1/ln2
|
||||
ivln2_l = <f32>7.0526075433e-06; // 0x36eca570 =1/ln2 tail
|
||||
|
||||
var hx = reinterpret<i32>(x); // GET_FLOAT_WORD(hx, x)
|
||||
var hy = reinterpret<i32>(y); // GET_FLOAT_WORD(hy, y)
|
||||
var ix = hx & 0x7fffffff;
|
||||
var iy = hy & 0x7fffffff;
|
||||
|
||||
// x**0 = 1, even if x is NaN
|
||||
if (iy == 0) return 1.0;
|
||||
// 1**y = 1, even if y is NaN
|
||||
if (hx == 0x3f800000) return 1.0;
|
||||
// NaN if either arg is NaN
|
||||
if (ix > 0x7f800000 || iy > 0x7f800000) return x + y;
|
||||
|
||||
// determine if y is an odd int when x < 0
|
||||
// yisint = 0 ... y is not an integer
|
||||
// yisint = 1 ... y is an odd int
|
||||
// yisint = 2 ... y is an even int
|
||||
var yisint = 0, j: i32, k: i32;
|
||||
if (hx < 0) {
|
||||
if (iy >= 0x4b800000) yisint = 2; // even integer y
|
||||
else if (iy >= 0x3f800000) {
|
||||
k = (iy >> 23) - 0x7f; // exponent
|
||||
j = iy >> (23 - k);
|
||||
if ((j << (23 - k)) == iy) yisint = 2 - (j & 1);
|
||||
}
|
||||
}
|
||||
|
||||
// special value of y
|
||||
if (iy == 0x7f800000) { // y is +-inf
|
||||
if (ix == 0x3f800000) return 1.0; // (-1)**+-inf is 1
|
||||
else if (ix > 0x3f800000) return hy >= 0 ? y : 0.0; // (|x|>1)**+-inf = inf,0
|
||||
else return hy >= 0 ? 0.0 : -y; // (|x|<1)**+-inf = 0,inf
|
||||
}
|
||||
if (iy == 0x3f800000) return hy >= 0 ? x : 1.0 / x; // y is +-1
|
||||
if (hy == 0x40000000) return x * x; // y is 2
|
||||
if (hy == 0x3f000000) { // y is 0.5
|
||||
if (hx >= 0) return builtin_sqrt<f32>(x); // x >= +0
|
||||
}
|
||||
|
||||
var ax = builtin_abs<f32>(x);
|
||||
// special value of x
|
||||
var z: f32;
|
||||
if (ix == 0x7f800000 || ix == 0 || ix == 0x3f800000) { // x is +-0,+-inf,+-1
|
||||
z = ax;
|
||||
if (hy < 0) z = 1.0 / z; // z = (1/|x|)
|
||||
if (hx < 0) {
|
||||
if (((ix - 0x3f800000) | yisint) == 0) z = (z - z) / (z - z); // (-1)**non-int is NaN
|
||||
else if (yisint == 1) z = -z; // (x<0)**odd = -(|x|**odd)
|
||||
}
|
||||
return z;
|
||||
}
|
||||
|
||||
var sn = <f32>1.0; // sign of result
|
||||
if (hx < 0) {
|
||||
if (yisint == 0) return (x - x) / (x - x); // (x<0)**(non-int) is NaN
|
||||
if (yisint == 1) sn = -1.0; // (x<0)**(odd int)
|
||||
}
|
||||
|
||||
// |y| is huge
|
||||
var t1: f32, t2: f32, r: f32, s: f32, t: f32, u: f32, v: f32, w: f32, p_h: f32, p_l: f32;
|
||||
var n: i32, is: i32;
|
||||
if (iy > 0x4d000000) { // if |y| > 2**27
|
||||
// over/underflow if x is not close to one
|
||||
if (ix < 0x3f7ffff8) return hy < 0 ? sn * huge * huge : sn * tiny * tiny;
|
||||
if (ix > 0x3f800007) return hy > 0 ? sn * huge * huge : sn * tiny * tiny;
|
||||
// now |1-x| is tiny <= 2**-20, suffice to compute
|
||||
// log(x) by x-x^2/2+x^3/3-x^4/4
|
||||
t = ax - 1; // t has 20 trailing zeros
|
||||
w = (t * t) * (0.5 - t * (0.333333333333 - t * 0.25));
|
||||
u = ivln2_h * t; // ivln2_h has 16 sig. bits
|
||||
v = t * ivln2_l - w * ivln2;
|
||||
t1 = u + v;
|
||||
is = reinterpret<i32>(t1); // GET_FLOAT_WORD(is, t1)
|
||||
t1 = reinterpret<f32>(is & 0xfffff000); // SET_FLOAT_WORD(t1, is & 0xfffff000)
|
||||
t2 = v - (t1 - u);
|
||||
} else {
|
||||
let s2: f32, s_h: f32, s_l: f32, t_h: f32, t_l: f32;
|
||||
n = 0;
|
||||
// take care subnormal number
|
||||
if (ix < 0x00800000) {
|
||||
ax *= two24;
|
||||
n -= 24;
|
||||
ix = reinterpret<i32>(ax); // GET_FLOAT_WORD(ix, ax)
|
||||
}
|
||||
n += (ix >> 23) - 0x7f;
|
||||
j = ix & 0x007fffff;
|
||||
// determine interval
|
||||
ix = j | 0x3f800000; // normalize ix
|
||||
if (j <= 0x1cc471) k = 0; // |x|<sqrt(3/2)
|
||||
else if (j < 0x5db3d7) k = 1; // |x|<sqrt(3)
|
||||
else {
|
||||
k = 0;
|
||||
n += 1;
|
||||
ix -= 0x00800000;
|
||||
}
|
||||
ax = reinterpret<f32>(ix); // SET_FLOAT_WORD(ax, ix)
|
||||
|
||||
// compute s = s_h+s_l = (x-1)/(x+1) or (x-1.5)/(x+1.5)
|
||||
let bp = select<f32>(1.5, 1.0, k); // bp[k], [1.0, 1.5]
|
||||
u = ax - bp;
|
||||
v = 1.0 / (ax + bp);
|
||||
s = u * v;
|
||||
s_h = s;
|
||||
is = reinterpret<u32>(s_h); // GET_FLOAT_WORD(is, s_h)
|
||||
s_h = reinterpret<f32>(is & 0xfffff000); // SET_FLOAT_WORD(s_h, is & 0xfffff000)
|
||||
// t_h=ax+bp[k] High
|
||||
is = ((ix >> 1) & 0xfffff000) | 0x20000000;
|
||||
t_h = reinterpret<f32>(is + 0x00400000 + (k << 21)); // SET_FLOAT_WORD(t_h, is + 0x00400000 + (k<<21))
|
||||
t_l = ax - (t_h - bp);
|
||||
s_l = v * ((u - s_h * t_h) - s_h * t_l);
|
||||
// compute log(ax)
|
||||
s2 = s * s;
|
||||
r = s2 * s2 * (L1 + s2 * (L2 + s2 * (L3 + s2 * (L4 + s2 * (L5 + s2 * L6)))));
|
||||
r += s_l * (s_h + s);
|
||||
s2 = s_h * s_h;
|
||||
t_h = 3.0 + s2 + r;
|
||||
is = reinterpret<u32>(t_h); // GET_FLOAT_WORD(is, t_h)
|
||||
t_h = reinterpret<f32>(is & 0xfffff000); // SET_FLOAT_WORD(t_h, is & 0xfffff000)
|
||||
t_l = r - ((t_h - 3.0) - s2);
|
||||
// u+v = s*(1+...)
|
||||
u = s_h * t_h;
|
||||
v = s_l * t_h + t_l * s;
|
||||
// 2/(3log2)*(s+...)
|
||||
p_h = u + v;
|
||||
is = reinterpret<u32>(p_h); // GET_FLOAT_WORD(is, p_h)
|
||||
p_h = reinterpret<f32>(is & 0xfffff000); // SET_FLOAT_WORD(p_h, is & 0xfffff000)
|
||||
p_l = v - (p_h - u);
|
||||
let z_h = cp_h * p_h; // cp_h+cp_l = 2/(3*log2)
|
||||
let dp_l = select<f32>(1.56322085e-06, 0.0, k); // dp_l[k], [0.0, 1.56322085e-06]
|
||||
let z_l = cp_l * p_h + p_l * cp + dp_l;
|
||||
// log2(ax) = (s+..)*2/(3*log2) = n + dp_h + z_h + z_l
|
||||
t = <f32>n;
|
||||
let dp_h = select<f32>(5.84960938e-01, 0.0, k); // dp_h[k], [0.0, 5.84960938e-01]
|
||||
t1 = (((z_h + z_l) + dp_h) + t);
|
||||
is = reinterpret<u32>(t1); // GET_FLOAT_WORD(is, t1)
|
||||
t1 = reinterpret<f32>(is & 0xfffff000); // SET_FLOAT_WORD(t1, is & 0xfffff000)
|
||||
t2 = z_l - (((t1 - t) - dp_h) - z_h);
|
||||
}
|
||||
|
||||
// split up y into y1+y2 and compute (y1+y2)*(t1+t2)
|
||||
is = reinterpret<u32>(y); // GET_FLOAT_WORD(is, y)
|
||||
var y1 = reinterpret<f32>(is & 0xfffff000); // SET_FLOAT_WORD(y1, is & 0xfffff000)
|
||||
p_l = (y - y1) * t1 + y * t2;
|
||||
p_h = y1 * t1;
|
||||
z = p_l + p_h;
|
||||
j = reinterpret<u32>(z); // GET_FLOAT_WORD(j, z)
|
||||
if (j > 0x43000000) { // if z > 128, overflow
|
||||
return sn * huge * huge;
|
||||
} else if (j == 0x43000000) { // if z == 128
|
||||
if (p_l + ovt > z - p_h) return sn * huge * huge; // overflow
|
||||
} else if ((j & 0x7fffffff) > 0x43160000) { // z < -150, FIXME: check should be (uint32_t)j > 0xc3160000
|
||||
return sn * tiny * tiny; // underflow
|
||||
} else if (j == 0xc3160000) { // z == -150
|
||||
if (p_l <= z - p_h) return sn * tiny * tiny; // underflow
|
||||
}
|
||||
|
||||
// compute 2**(p_h+p_l)
|
||||
var i = j & 0x7fffffff;
|
||||
k = (i >> 23) - 0x7f;
|
||||
n = 0;
|
||||
if (i > 0x3f000000) { // if |z| > 0.5, set n = [z+0.5]
|
||||
n = j + (0x00800000 >> (k + 1));
|
||||
k = ((n & 0x7fffffff) >> 23) - 0x7f; // new k for n
|
||||
t = reinterpret<f32>(n & ~(0x007fffff >> k)); // SET_FLOAT_WORD(t, n & ~(0x007fffff>>k))
|
||||
n = ((n & 0x007fffff) | 0x00800000) >> (23 - k);
|
||||
if (j < 0) n = -n;
|
||||
p_h -= t;
|
||||
}
|
||||
t = p_l + p_h;
|
||||
is = reinterpret<u32>(t); // GET_FLOAT_WORD(is, t)
|
||||
t = reinterpret<f32>(is & 0xffff8000); // SET_FLOAT_WORD(t, is & 0xffff8000);
|
||||
u = t * lg2_h;
|
||||
v = (p_l - (t - p_h)) * lg2 + t * lg2_l;
|
||||
z = u + v;
|
||||
w = v - (z - u);
|
||||
t = z * z;
|
||||
t1 = z - t * (P1 + t * (P2 + t * (P3 + t * (P4 + t * P5))));
|
||||
r = (z * t1) / (t1 - 2.0) - (w + z * w);
|
||||
z = 1.0 - (r - z);
|
||||
j = reinterpret<u32>(z); // GET_FLOAT_WORD(j, z)
|
||||
j += n << 23;
|
||||
if ((j >> 23) <= 0) z = scalbnf(z, n); // subnormal output
|
||||
else z = reinterpret<f32>(j); // SET_FLOAT_WORD(z, j)
|
||||
return sn * z;
|
||||
}
|
||||
|
||||
export function round(x: f32): f32 {
|
||||
return builtin_nearest(x);
|
||||
}
|
||||
|
@ -109,21 +109,25 @@ tests.forEach(filename => {
|
||||
|
||||
// Instantiate
|
||||
try {
|
||||
let exports = new WebAssembly.Instance(new WebAssembly.Module(stdout.toBuffer()), {
|
||||
env: {
|
||||
abort: function(msg, file, line, column) {
|
||||
// TODO
|
||||
let runTime = asc.measure(() => {
|
||||
let exports = new WebAssembly.Instance(new WebAssembly.Module(stdout.toBuffer()), {
|
||||
env: {
|
||||
abort: function(msg, file, line, column) {
|
||||
// TODO
|
||||
},
|
||||
externalFunction: function() { },
|
||||
externalConstant: 1,
|
||||
logi: function(i) { console.log("logi: " + i); },
|
||||
logf: function(f) { console.log("logf: " + f); }
|
||||
},
|
||||
externalFunction: function() { },
|
||||
externalConstant: 1
|
||||
},
|
||||
my: {
|
||||
externalFunction: function() { },
|
||||
externalConstant: 2
|
||||
},
|
||||
JSMath: Math
|
||||
my: {
|
||||
externalFunction: function() { },
|
||||
externalConstant: 2
|
||||
},
|
||||
JSMath: Math
|
||||
});
|
||||
});
|
||||
console.log("- " + chalk.green("instantiate OK"));
|
||||
console.log("- " + chalk.green("instantiate OK") + " (" + asc.formatTime(runTime) + ")");
|
||||
} catch (e) {
|
||||
console.log("- " + chalk.red("instantiate ERROR: ") + e);
|
||||
failed = true;
|
||||
|
@ -2729,9 +2729,7 @@
|
||||
(i32.eqz
|
||||
(i32.eq
|
||||
(i32.const -2147483648)
|
||||
(i32.wrap/i64
|
||||
(i64.const 2147483648)
|
||||
)
|
||||
(i32.const -2147483648)
|
||||
)
|
||||
)
|
||||
(block
|
||||
|
@ -6230,9 +6230,7 @@
|
||||
(i32.eqz
|
||||
(i32.eq
|
||||
(i32.const -2147483648)
|
||||
(i32.wrap/i64
|
||||
(i64.const 2147483648)
|
||||
)
|
||||
(i32.const -2147483648)
|
||||
)
|
||||
)
|
||||
(block
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -17,295 +17,515 @@ function check<T>(actual: T, expected: T, error: T, flags: i32): void { // TODO:
|
||||
|
||||
// ================================ built-in fmod ================================
|
||||
|
||||
function builtin_fmod(left: f64, right: f64, expected: f64, error: f64, flags: i32): void {
|
||||
check<f64>(fmod(left, right), expected, error, flags);
|
||||
function test_fmod(left: f64, right: f64, expected: f64, error: f64, flags: i32): void {
|
||||
check<f64>(left % right, expected, error, flags);
|
||||
}
|
||||
|
||||
// sanity
|
||||
builtin_fmod(-8.06684839057968084, 4.53566256067686879, -3.53118582990281205, 0.00000000000000000, 0);
|
||||
builtin_fmod(4.34523984933830487, -8.88799136300345083, 4.34523984933830487, 0.00000000000000000, 0);
|
||||
builtin_fmod(-8.38143342755524934, -2.76360733737958819, -0.0906114154164847641, 0.00000000000000000, 0);
|
||||
builtin_fmod(-6.53167358191348413, 4.56753527684274374, -1.96413830507074039, 0.00000000000000000, 0);
|
||||
builtin_fmod(9.26705696697258574, 4.81139208435979615, 4.45566488261278959, 0.00000000000000000, 0);
|
||||
builtin_fmod(-6.45004555606023633, 0.662071792337673881, -0.491399425021171399, 0.00000000000000000, 0);
|
||||
builtin_fmod(7.85889025304169664, 0.0521545267500622481, 0.0357112405323594256, 0.00000000000000000, 0);
|
||||
builtin_fmod(-0.792054511984895959, 7.67640268511753998, -0.792054511984895959, 0.00000000000000000, 0);
|
||||
builtin_fmod(0.615702673197924044, 2.01190257903248026, 0.615702673197924044, 0.00000000000000000, 0);
|
||||
builtin_fmod(-0.558758682360915193, 0.0322398306026380407, -0.0106815621160685006, 0.00000000000000000, 0);
|
||||
test_fmod(-8.06684839057968084, 4.53566256067686879, -3.53118582990281205, 0.00000000000000000, 0);
|
||||
test_fmod(4.34523984933830487, -8.88799136300345083, 4.34523984933830487, 0.00000000000000000, 0);
|
||||
test_fmod(-8.38143342755524934, -2.76360733737958819, -0.0906114154164847641, 0.00000000000000000, 0);
|
||||
test_fmod(-6.53167358191348413, 4.56753527684274374, -1.96413830507074039, 0.00000000000000000, 0);
|
||||
test_fmod(9.26705696697258574, 4.81139208435979615, 4.45566488261278959, 0.00000000000000000, 0);
|
||||
test_fmod(-6.45004555606023633, 0.662071792337673881, -0.491399425021171399, 0.00000000000000000, 0);
|
||||
test_fmod(7.85889025304169664, 0.0521545267500622481, 0.0357112405323594256, 0.00000000000000000, 0);
|
||||
test_fmod(-0.792054511984895959, 7.67640268511753998, -0.792054511984895959, 0.00000000000000000, 0);
|
||||
test_fmod(0.615702673197924044, 2.01190257903248026, 0.615702673197924044, 0.00000000000000000, 0);
|
||||
test_fmod(-0.558758682360915193, 0.0322398306026380407, -0.0106815621160685006, 0.00000000000000000, 0);
|
||||
|
||||
// special
|
||||
builtin_fmod(0.00000000000000000, 1.00000000000000000, 0.00000000000000000, 0.00000000000000000, 0);
|
||||
builtin_fmod(-0.00000000000000000, 1.00000000000000000, -0.00000000000000000, 0.00000000000000000, 0);
|
||||
builtin_fmod(0.500000000000000000, 1.00000000000000000, 0.500000000000000000, 0.00000000000000000, 0);
|
||||
builtin_fmod(-0.500000000000000000, 1.00000000000000000, -0.500000000000000000, 0.00000000000000000, 0);
|
||||
builtin_fmod(1.00000000000000000, 1.00000000000000000, 0.00000000000000000, 0.00000000000000000, 0);
|
||||
builtin_fmod(-1.00000000000000000, 1.00000000000000000, -0.00000000000000000, 0.00000000000000000, 0);
|
||||
builtin_fmod(1.50000000000000000, 1.00000000000000000, 0.500000000000000000, 0.00000000000000000, 0);
|
||||
builtin_fmod(-1.50000000000000000, 1.00000000000000000, -0.500000000000000000, 0.00000000000000000, 0);
|
||||
builtin_fmod(2.00000000000000000, 1.00000000000000000, 0.00000000000000000, 0.00000000000000000, 0);
|
||||
builtin_fmod(-2.00000000000000000, 1.00000000000000000, -0.00000000000000000, 0.00000000000000000, 0);
|
||||
builtin_fmod(Infinity, 1.00000000000000000, NaN, 0.00000000000000000, INVALID);
|
||||
builtin_fmod(-Infinity, 1.00000000000000000, NaN, 0.00000000000000000, INVALID);
|
||||
builtin_fmod(NaN, 1.00000000000000000, NaN, 0.00000000000000000, 0);
|
||||
builtin_fmod(0.00000000000000000, -1.00000000000000000, 0.00000000000000000, 0.00000000000000000, 0);
|
||||
builtin_fmod(-0.00000000000000000, -1.00000000000000000, -0.00000000000000000, 0.00000000000000000, 0);
|
||||
builtin_fmod(0.500000000000000000, -1.00000000000000000, 0.500000000000000000, 0.00000000000000000, 0);
|
||||
builtin_fmod(-0.500000000000000000, -1.00000000000000000, -0.500000000000000000, 0.00000000000000000, 0);
|
||||
builtin_fmod(1.00000000000000000, -1.00000000000000000, 0.00000000000000000, 0.00000000000000000, 0);
|
||||
builtin_fmod(-1.00000000000000000, -1.00000000000000000, -0.00000000000000000, 0.00000000000000000, 0);
|
||||
builtin_fmod(1.50000000000000000, -1.00000000000000000, 0.500000000000000000, 0.00000000000000000, 0);
|
||||
builtin_fmod(-1.50000000000000000, -1.00000000000000000, -0.500000000000000000, 0.00000000000000000, 0);
|
||||
builtin_fmod(2.00000000000000000, -1.00000000000000000, 0.00000000000000000, 0.00000000000000000, 0);
|
||||
builtin_fmod(-2.00000000000000000, -1.00000000000000000, -0.00000000000000000, 0.00000000000000000, 0);
|
||||
builtin_fmod(Infinity, -1.00000000000000000, NaN, 0.00000000000000000, INVALID);
|
||||
builtin_fmod(-Infinity, -1.00000000000000000, NaN, 0.00000000000000000, INVALID);
|
||||
builtin_fmod(NaN, -1.00000000000000000, NaN, 0.00000000000000000, 0);
|
||||
builtin_fmod(0.00000000000000000, 0.00000000000000000, NaN, 0.00000000000000000, INVALID);
|
||||
builtin_fmod(0.00000000000000000, -0.00000000000000000, NaN, 0.00000000000000000, INVALID);
|
||||
builtin_fmod(0.00000000000000000, Infinity, 0.00000000000000000, 0.00000000000000000, 0);
|
||||
builtin_fmod(0.00000000000000000, -Infinity, 0.00000000000000000, 0.00000000000000000, 0);
|
||||
builtin_fmod(0.00000000000000000, NaN, NaN, 0.00000000000000000, 0);
|
||||
builtin_fmod(-0.00000000000000000, 0.00000000000000000, NaN, 0.00000000000000000, INVALID);
|
||||
builtin_fmod(-0.00000000000000000, -0.00000000000000000, NaN, 0.00000000000000000, INVALID);
|
||||
builtin_fmod(-0.00000000000000000, Infinity, -0.00000000000000000, 0.00000000000000000, 0);
|
||||
builtin_fmod(-0.00000000000000000, -Infinity, -0.00000000000000000, 0.00000000000000000, 0);
|
||||
builtin_fmod(-0.00000000000000000, NaN, NaN, 0.00000000000000000, 0);
|
||||
builtin_fmod(1.00000000000000000, 0.00000000000000000, NaN, 0.00000000000000000, INVALID);
|
||||
builtin_fmod(-1.00000000000000000, 0.00000000000000000, NaN, 0.00000000000000000, INVALID);
|
||||
builtin_fmod(Infinity, 0.00000000000000000, NaN, 0.00000000000000000, INVALID);
|
||||
builtin_fmod(-Infinity, 0.00000000000000000, NaN, 0.00000000000000000, INVALID);
|
||||
builtin_fmod(NaN, 0.00000000000000000, NaN, 0.00000000000000000, 0);
|
||||
builtin_fmod(-1.00000000000000000, -0.00000000000000000, NaN, 0.00000000000000000, INVALID);
|
||||
builtin_fmod(Infinity, -0.00000000000000000, NaN, 0.00000000000000000, INVALID);
|
||||
builtin_fmod(-Infinity, -0.00000000000000000, NaN, 0.00000000000000000, INVALID);
|
||||
builtin_fmod(NaN, -0.00000000000000000, NaN, 0.00000000000000000, 0);
|
||||
builtin_fmod(Infinity, 2.00000000000000000, NaN, 0.00000000000000000, INVALID);
|
||||
builtin_fmod(Infinity, -0.500000000000000000, NaN, 0.00000000000000000, INVALID);
|
||||
builtin_fmod(Infinity, NaN, NaN, 0.00000000000000000, 0);
|
||||
builtin_fmod(-Infinity, 2.00000000000000000, NaN, 0.00000000000000000, INVALID);
|
||||
builtin_fmod(-Infinity, -0.500000000000000000, NaN, 0.00000000000000000, INVALID);
|
||||
builtin_fmod(-Infinity, NaN, NaN, 0.00000000000000000, 0);
|
||||
builtin_fmod(NaN, NaN, NaN, 0.00000000000000000, 0);
|
||||
builtin_fmod(1.00000000000000000, NaN, NaN, 0.00000000000000000, 0);
|
||||
builtin_fmod(-1.00000000000000000, NaN, NaN, 0.00000000000000000, 0);
|
||||
builtin_fmod(1.00000000000000000, Infinity, 1.00000000000000000, 0.00000000000000000, 0);
|
||||
builtin_fmod(-1.00000000000000000, Infinity, -1.00000000000000000, 0.00000000000000000, 0);
|
||||
builtin_fmod(Infinity, Infinity, NaN, 0.00000000000000000, INVALID);
|
||||
builtin_fmod(-Infinity, Infinity, NaN, 0.00000000000000000, INVALID);
|
||||
builtin_fmod(1.00000000000000000, -Infinity, 1.00000000000000000, 0.00000000000000000, 0);
|
||||
builtin_fmod(-1.00000000000000000, -Infinity, -1.00000000000000000, 0.00000000000000000, 0);
|
||||
builtin_fmod(Infinity, -Infinity, NaN, 0.00000000000000000, INVALID);
|
||||
builtin_fmod(-Infinity, -Infinity, NaN, 0.00000000000000000, INVALID);
|
||||
builtin_fmod(1.75000000000000000, 0.500000000000000000, 0.250000000000000000, 0.00000000000000000, 0);
|
||||
builtin_fmod(-1.75000000000000000, 0.500000000000000000, -0.250000000000000000, 0.00000000000000000, 0);
|
||||
builtin_fmod(1.75000000000000000, -0.500000000000000000, 0.250000000000000000, 0.00000000000000000, 0);
|
||||
builtin_fmod(-1.75000000000000000, -0.500000000000000000, -0.250000000000000000, 0.00000000000000000, 0);
|
||||
test_fmod(0.00000000000000000, 1.00000000000000000, 0.00000000000000000, 0.00000000000000000, 0);
|
||||
test_fmod(-0.00000000000000000, 1.00000000000000000, -0.00000000000000000, 0.00000000000000000, 0);
|
||||
test_fmod(0.500000000000000000, 1.00000000000000000, 0.500000000000000000, 0.00000000000000000, 0);
|
||||
test_fmod(-0.500000000000000000, 1.00000000000000000, -0.500000000000000000, 0.00000000000000000, 0);
|
||||
test_fmod(1.00000000000000000, 1.00000000000000000, 0.00000000000000000, 0.00000000000000000, 0);
|
||||
test_fmod(-1.00000000000000000, 1.00000000000000000, -0.00000000000000000, 0.00000000000000000, 0);
|
||||
test_fmod(1.50000000000000000, 1.00000000000000000, 0.500000000000000000, 0.00000000000000000, 0);
|
||||
test_fmod(-1.50000000000000000, 1.00000000000000000, -0.500000000000000000, 0.00000000000000000, 0);
|
||||
test_fmod(2.00000000000000000, 1.00000000000000000, 0.00000000000000000, 0.00000000000000000, 0);
|
||||
test_fmod(-2.00000000000000000, 1.00000000000000000, -0.00000000000000000, 0.00000000000000000, 0);
|
||||
test_fmod(Infinity, 1.00000000000000000, NaN, 0.00000000000000000, INVALID);
|
||||
test_fmod(-Infinity, 1.00000000000000000, NaN, 0.00000000000000000, INVALID);
|
||||
test_fmod(NaN, 1.00000000000000000, NaN, 0.00000000000000000, 0);
|
||||
test_fmod(0.00000000000000000, -1.00000000000000000, 0.00000000000000000, 0.00000000000000000, 0);
|
||||
test_fmod(-0.00000000000000000, -1.00000000000000000, -0.00000000000000000, 0.00000000000000000, 0);
|
||||
test_fmod(0.500000000000000000, -1.00000000000000000, 0.500000000000000000, 0.00000000000000000, 0);
|
||||
test_fmod(-0.500000000000000000, -1.00000000000000000, -0.500000000000000000, 0.00000000000000000, 0);
|
||||
test_fmod(1.00000000000000000, -1.00000000000000000, 0.00000000000000000, 0.00000000000000000, 0);
|
||||
test_fmod(-1.00000000000000000, -1.00000000000000000, -0.00000000000000000, 0.00000000000000000, 0);
|
||||
test_fmod(1.50000000000000000, -1.00000000000000000, 0.500000000000000000, 0.00000000000000000, 0);
|
||||
test_fmod(-1.50000000000000000, -1.00000000000000000, -0.500000000000000000, 0.00000000000000000, 0);
|
||||
test_fmod(2.00000000000000000, -1.00000000000000000, 0.00000000000000000, 0.00000000000000000, 0);
|
||||
test_fmod(-2.00000000000000000, -1.00000000000000000, -0.00000000000000000, 0.00000000000000000, 0);
|
||||
test_fmod(Infinity, -1.00000000000000000, NaN, 0.00000000000000000, INVALID);
|
||||
test_fmod(-Infinity, -1.00000000000000000, NaN, 0.00000000000000000, INVALID);
|
||||
test_fmod(NaN, -1.00000000000000000, NaN, 0.00000000000000000, 0);
|
||||
test_fmod(0.00000000000000000, 0.00000000000000000, NaN, 0.00000000000000000, INVALID);
|
||||
test_fmod(0.00000000000000000, -0.00000000000000000, NaN, 0.00000000000000000, INVALID);
|
||||
test_fmod(0.00000000000000000, Infinity, 0.00000000000000000, 0.00000000000000000, 0);
|
||||
test_fmod(0.00000000000000000, -Infinity, 0.00000000000000000, 0.00000000000000000, 0);
|
||||
test_fmod(0.00000000000000000, NaN, NaN, 0.00000000000000000, 0);
|
||||
test_fmod(-0.00000000000000000, 0.00000000000000000, NaN, 0.00000000000000000, INVALID);
|
||||
test_fmod(-0.00000000000000000, -0.00000000000000000, NaN, 0.00000000000000000, INVALID);
|
||||
test_fmod(-0.00000000000000000, Infinity, -0.00000000000000000, 0.00000000000000000, 0);
|
||||
test_fmod(-0.00000000000000000, -Infinity, -0.00000000000000000, 0.00000000000000000, 0);
|
||||
test_fmod(-0.00000000000000000, NaN, NaN, 0.00000000000000000, 0);
|
||||
test_fmod(1.00000000000000000, 0.00000000000000000, NaN, 0.00000000000000000, INVALID);
|
||||
test_fmod(-1.00000000000000000, 0.00000000000000000, NaN, 0.00000000000000000, INVALID);
|
||||
test_fmod(Infinity, 0.00000000000000000, NaN, 0.00000000000000000, INVALID);
|
||||
test_fmod(-Infinity, 0.00000000000000000, NaN, 0.00000000000000000, INVALID);
|
||||
test_fmod(NaN, 0.00000000000000000, NaN, 0.00000000000000000, 0);
|
||||
test_fmod(-1.00000000000000000, -0.00000000000000000, NaN, 0.00000000000000000, INVALID);
|
||||
test_fmod(Infinity, -0.00000000000000000, NaN, 0.00000000000000000, INVALID);
|
||||
test_fmod(-Infinity, -0.00000000000000000, NaN, 0.00000000000000000, INVALID);
|
||||
test_fmod(NaN, -0.00000000000000000, NaN, 0.00000000000000000, 0);
|
||||
test_fmod(Infinity, 2.00000000000000000, NaN, 0.00000000000000000, INVALID);
|
||||
test_fmod(Infinity, -0.500000000000000000, NaN, 0.00000000000000000, INVALID);
|
||||
test_fmod(Infinity, NaN, NaN, 0.00000000000000000, 0);
|
||||
test_fmod(-Infinity, 2.00000000000000000, NaN, 0.00000000000000000, INVALID);
|
||||
test_fmod(-Infinity, -0.500000000000000000, NaN, 0.00000000000000000, INVALID);
|
||||
test_fmod(-Infinity, NaN, NaN, 0.00000000000000000, 0);
|
||||
test_fmod(NaN, NaN, NaN, 0.00000000000000000, 0);
|
||||
test_fmod(1.00000000000000000, NaN, NaN, 0.00000000000000000, 0);
|
||||
test_fmod(-1.00000000000000000, NaN, NaN, 0.00000000000000000, 0);
|
||||
test_fmod(1.00000000000000000, Infinity, 1.00000000000000000, 0.00000000000000000, 0);
|
||||
test_fmod(-1.00000000000000000, Infinity, -1.00000000000000000, 0.00000000000000000, 0);
|
||||
test_fmod(Infinity, Infinity, NaN, 0.00000000000000000, INVALID);
|
||||
test_fmod(-Infinity, Infinity, NaN, 0.00000000000000000, INVALID);
|
||||
test_fmod(1.00000000000000000, -Infinity, 1.00000000000000000, 0.00000000000000000, 0);
|
||||
test_fmod(-1.00000000000000000, -Infinity, -1.00000000000000000, 0.00000000000000000, 0);
|
||||
test_fmod(Infinity, -Infinity, NaN, 0.00000000000000000, INVALID);
|
||||
test_fmod(-Infinity, -Infinity, NaN, 0.00000000000000000, INVALID);
|
||||
test_fmod(1.75000000000000000, 0.500000000000000000, 0.250000000000000000, 0.00000000000000000, 0);
|
||||
test_fmod(-1.75000000000000000, 0.500000000000000000, -0.250000000000000000, 0.00000000000000000, 0);
|
||||
test_fmod(1.75000000000000000, -0.500000000000000000, 0.250000000000000000, 0.00000000000000000, 0);
|
||||
test_fmod(-1.75000000000000000, -0.500000000000000000, -0.250000000000000000, 0.00000000000000000, 0);
|
||||
|
||||
// ================================ built-in fmodf ================================
|
||||
|
||||
function builtin_fmodf(left: f32, right: f32, expected: f32, error: f32, flags: i32): void {
|
||||
check<f32>(fmodf(left, right), expected, error, flags);
|
||||
function test_fmodf(left: f32, right: f32, expected: f32, error: f32, flags: i32): void {
|
||||
check<f32>(left % right, expected, error, flags);
|
||||
}
|
||||
|
||||
// sanity
|
||||
builtin_fmodf(-8.066848755, 4.535662651, -3.531186104, 0.000000000, 0);
|
||||
builtin_fmodf(4.345239639, -8.887990952, 4.345239639, 0.000000000, 0);
|
||||
builtin_fmodf(-8.381433487, -2.763607264, -0.09061169624, 0.000000000, 0);
|
||||
builtin_fmodf(-6.531673431, 4.567535400, -1.964138031, 0.000000000, 0);
|
||||
builtin_fmodf(9.267057419, 4.811392307, 4.455665112, 0.000000000, 0);
|
||||
builtin_fmodf(-6.450045586, 0.6620717645, -0.4913997054, 0.000000000, 0);
|
||||
builtin_fmodf(7.858890057, 0.05215452611, 0.03571113944, 0.000000000, 0);
|
||||
builtin_fmodf(-0.7920545340, 7.676402569, -0.7920545340, 0.000000000, 0);
|
||||
builtin_fmodf(0.6157026887, 2.011902571, 0.6157026887, 0.000000000, 0);
|
||||
builtin_fmodf(-0.5587586761, 0.03223983198, -0.01068153232, 0.000000000, 0);
|
||||
test_fmodf(-8.066848755, 4.535662651, -3.531186104, 0.000000000, 0);
|
||||
test_fmodf(4.345239639, -8.887990952, 4.345239639, 0.000000000, 0);
|
||||
test_fmodf(-8.381433487, -2.763607264, -0.09061169624, 0.000000000, 0);
|
||||
test_fmodf(-6.531673431, 4.567535400, -1.964138031, 0.000000000, 0);
|
||||
test_fmodf(9.267057419, 4.811392307, 4.455665112, 0.000000000, 0);
|
||||
test_fmodf(-6.450045586, 0.6620717645, -0.4913997054, 0.000000000, 0);
|
||||
test_fmodf(7.858890057, 0.05215452611, 0.03571113944, 0.000000000, 0);
|
||||
test_fmodf(-0.7920545340, 7.676402569, -0.7920545340, 0.000000000, 0);
|
||||
test_fmodf(0.6157026887, 2.011902571, 0.6157026887, 0.000000000, 0);
|
||||
test_fmodf(-0.5587586761, 0.03223983198, -0.01068153232, 0.000000000, 0);
|
||||
|
||||
// special
|
||||
builtin_fmodf(0.000000000, 1.000000000, 0.000000000, 0.000000000, 0);
|
||||
builtin_fmodf(-0.000000000, 1.000000000, -0.000000000, 0.000000000, 0);
|
||||
builtin_fmodf(0.5000000000, 1.000000000, 0.5000000000, 0.000000000, 0);
|
||||
builtin_fmodf(-0.5000000000, 1.000000000, -0.5000000000, 0.000000000, 0);
|
||||
builtin_fmodf(1.000000000, 1.000000000, 0.000000000, 0.000000000, 0);
|
||||
builtin_fmodf(-1.000000000, 1.000000000, -0.000000000, 0.000000000, 0);
|
||||
builtin_fmodf(1.500000000, 1.000000000, 0.5000000000, 0.000000000, 0);
|
||||
builtin_fmodf(-1.500000000, 1.000000000, -0.5000000000, 0.000000000, 0);
|
||||
builtin_fmodf(2.000000000, 1.000000000, 0.000000000, 0.000000000, 0);
|
||||
builtin_fmodf(-2.000000000, 1.000000000, -0.000000000, 0.000000000, 0);
|
||||
builtin_fmodf(Infinity, 1.000000000, NaN, 0.000000000, INVALID);
|
||||
builtin_fmodf(-Infinity, 1.000000000, NaN, 0.000000000, INVALID);
|
||||
builtin_fmodf(NaN, 1.000000000, NaN, 0.000000000, 0);
|
||||
builtin_fmodf(0.000000000, -1.000000000, 0.000000000, 0.000000000, 0);
|
||||
builtin_fmodf(-0.000000000, -1.000000000, -0.000000000, 0.000000000, 0);
|
||||
builtin_fmodf(0.5000000000, -1.000000000, 0.5000000000, 0.000000000, 0);
|
||||
builtin_fmodf(-0.5000000000, -1.000000000, -0.5000000000, 0.000000000, 0);
|
||||
builtin_fmodf(1.000000000, -1.000000000, 0.000000000, 0.000000000, 0);
|
||||
builtin_fmodf(-1.000000000, -1.000000000, -0.000000000, 0.000000000, 0);
|
||||
builtin_fmodf(1.500000000, -1.000000000, 0.5000000000, 0.000000000, 0);
|
||||
builtin_fmodf(-1.500000000, -1.000000000, -0.5000000000, 0.000000000, 0);
|
||||
builtin_fmodf(2.000000000, -1.000000000, 0.000000000, 0.000000000, 0);
|
||||
builtin_fmodf(-2.000000000, -1.000000000, -0.000000000, 0.000000000, 0);
|
||||
builtin_fmodf(Infinity, -1.000000000, NaN, 0.000000000, INVALID);
|
||||
builtin_fmodf(-Infinity, -1.000000000, NaN, 0.000000000, INVALID);
|
||||
builtin_fmodf(NaN, -1.000000000, NaN, 0.000000000, 0);
|
||||
builtin_fmodf(0.000000000, 0.000000000, NaN, 0.000000000, INVALID);
|
||||
builtin_fmodf(0.000000000, -0.000000000, NaN, 0.000000000, INVALID);
|
||||
builtin_fmodf(0.000000000, Infinity, 0.000000000, 0.000000000, 0);
|
||||
builtin_fmodf(0.000000000, -Infinity, 0.000000000, 0.000000000, 0);
|
||||
builtin_fmodf(0.000000000, NaN, NaN, 0.000000000, 0);
|
||||
builtin_fmodf(-0.000000000, 0.000000000, NaN, 0.000000000, INVALID);
|
||||
builtin_fmodf(-0.000000000, -0.000000000, NaN, 0.000000000, INVALID);
|
||||
builtin_fmodf(-0.000000000, Infinity, -0.000000000, 0.000000000, 0);
|
||||
builtin_fmodf(-0.000000000, -Infinity, -0.000000000, 0.000000000, 0);
|
||||
builtin_fmodf(-0.000000000, NaN, NaN, 0.000000000, 0);
|
||||
builtin_fmodf(1.000000000, 0.000000000, NaN, 0.000000000, INVALID);
|
||||
builtin_fmodf(-1.000000000, 0.000000000, NaN, 0.000000000, INVALID);
|
||||
builtin_fmodf(Infinity, 0.000000000, NaN, 0.000000000, INVALID);
|
||||
builtin_fmodf(-Infinity, 0.000000000, NaN, 0.000000000, INVALID);
|
||||
builtin_fmodf(NaN, 0.000000000, NaN, 0.000000000, 0);
|
||||
builtin_fmodf(-1.000000000, -0.000000000, NaN, 0.000000000, INVALID);
|
||||
builtin_fmodf(Infinity, -0.000000000, NaN, 0.000000000, INVALID);
|
||||
builtin_fmodf(-Infinity, -0.000000000, NaN, 0.000000000, INVALID);
|
||||
builtin_fmodf(NaN, -0.000000000, NaN, 0.000000000, 0);
|
||||
builtin_fmodf(Infinity, 2.000000000, NaN, 0.000000000, INVALID);
|
||||
builtin_fmodf(Infinity, -0.5000000000, NaN, 0.000000000, INVALID);
|
||||
builtin_fmodf(Infinity, NaN, NaN, 0.000000000, 0);
|
||||
builtin_fmodf(-Infinity, 2.000000000, NaN, 0.000000000, INVALID);
|
||||
builtin_fmodf(-Infinity, -0.5000000000, NaN, 0.000000000, INVALID);
|
||||
builtin_fmodf(-Infinity, NaN, NaN, 0.000000000, 0);
|
||||
builtin_fmodf(NaN, NaN, NaN, 0.000000000, 0);
|
||||
builtin_fmodf(1.000000000, NaN, NaN, 0.000000000, 0);
|
||||
builtin_fmodf(-1.000000000, NaN, NaN, 0.000000000, 0);
|
||||
builtin_fmodf(1.000000000, Infinity, 1.000000000, 0.000000000, 0);
|
||||
builtin_fmodf(-1.000000000, Infinity, -1.000000000, 0.000000000, 0);
|
||||
builtin_fmodf(Infinity, Infinity, NaN, 0.000000000, INVALID);
|
||||
builtin_fmodf(-Infinity, Infinity, NaN, 0.000000000, INVALID);
|
||||
builtin_fmodf(1.000000000, -Infinity, 1.000000000, 0.000000000, 0);
|
||||
builtin_fmodf(-1.000000000, -Infinity, -1.000000000, 0.000000000, 0);
|
||||
builtin_fmodf(Infinity, -Infinity, NaN, 0.000000000, INVALID);
|
||||
builtin_fmodf(-Infinity, -Infinity, NaN, 0.000000000, INVALID);
|
||||
builtin_fmodf(1.750000000, 0.5000000000, 0.2500000000, 0.000000000, 0);
|
||||
builtin_fmodf(-1.750000000, 0.5000000000, -0.2500000000, 0.000000000, 0);
|
||||
builtin_fmodf(1.750000000, -0.5000000000, 0.2500000000, 0.000000000, 0);
|
||||
builtin_fmodf(-1.750000000, -0.5000000000, -0.2500000000, 0.000000000, 0);
|
||||
test_fmodf(0.000000000, 1.000000000, 0.000000000, 0.000000000, 0);
|
||||
test_fmodf(-0.000000000, 1.000000000, -0.000000000, 0.000000000, 0);
|
||||
test_fmodf(0.5000000000, 1.000000000, 0.5000000000, 0.000000000, 0);
|
||||
test_fmodf(-0.5000000000, 1.000000000, -0.5000000000, 0.000000000, 0);
|
||||
test_fmodf(1.000000000, 1.000000000, 0.000000000, 0.000000000, 0);
|
||||
test_fmodf(-1.000000000, 1.000000000, -0.000000000, 0.000000000, 0);
|
||||
test_fmodf(1.500000000, 1.000000000, 0.5000000000, 0.000000000, 0);
|
||||
test_fmodf(-1.500000000, 1.000000000, -0.5000000000, 0.000000000, 0);
|
||||
test_fmodf(2.000000000, 1.000000000, 0.000000000, 0.000000000, 0);
|
||||
test_fmodf(-2.000000000, 1.000000000, -0.000000000, 0.000000000, 0);
|
||||
test_fmodf(Infinity, 1.000000000, NaN, 0.000000000, INVALID);
|
||||
test_fmodf(-Infinity, 1.000000000, NaN, 0.000000000, INVALID);
|
||||
test_fmodf(NaN, 1.000000000, NaN, 0.000000000, 0);
|
||||
test_fmodf(0.000000000, -1.000000000, 0.000000000, 0.000000000, 0);
|
||||
test_fmodf(-0.000000000, -1.000000000, -0.000000000, 0.000000000, 0);
|
||||
test_fmodf(0.5000000000, -1.000000000, 0.5000000000, 0.000000000, 0);
|
||||
test_fmodf(-0.5000000000, -1.000000000, -0.5000000000, 0.000000000, 0);
|
||||
test_fmodf(1.000000000, -1.000000000, 0.000000000, 0.000000000, 0);
|
||||
test_fmodf(-1.000000000, -1.000000000, -0.000000000, 0.000000000, 0);
|
||||
test_fmodf(1.500000000, -1.000000000, 0.5000000000, 0.000000000, 0);
|
||||
test_fmodf(-1.500000000, -1.000000000, -0.5000000000, 0.000000000, 0);
|
||||
test_fmodf(2.000000000, -1.000000000, 0.000000000, 0.000000000, 0);
|
||||
test_fmodf(-2.000000000, -1.000000000, -0.000000000, 0.000000000, 0);
|
||||
test_fmodf(Infinity, -1.000000000, NaN, 0.000000000, INVALID);
|
||||
test_fmodf(-Infinity, -1.000000000, NaN, 0.000000000, INVALID);
|
||||
test_fmodf(NaN, -1.000000000, NaN, 0.000000000, 0);
|
||||
test_fmodf(0.000000000, 0.000000000, NaN, 0.000000000, INVALID);
|
||||
test_fmodf(0.000000000, -0.000000000, NaN, 0.000000000, INVALID);
|
||||
test_fmodf(0.000000000, Infinity, 0.000000000, 0.000000000, 0);
|
||||
test_fmodf(0.000000000, -Infinity, 0.000000000, 0.000000000, 0);
|
||||
test_fmodf(0.000000000, NaN, NaN, 0.000000000, 0);
|
||||
test_fmodf(-0.000000000, 0.000000000, NaN, 0.000000000, INVALID);
|
||||
test_fmodf(-0.000000000, -0.000000000, NaN, 0.000000000, INVALID);
|
||||
test_fmodf(-0.000000000, Infinity, -0.000000000, 0.000000000, 0);
|
||||
test_fmodf(-0.000000000, -Infinity, -0.000000000, 0.000000000, 0);
|
||||
test_fmodf(-0.000000000, NaN, NaN, 0.000000000, 0);
|
||||
test_fmodf(1.000000000, 0.000000000, NaN, 0.000000000, INVALID);
|
||||
test_fmodf(-1.000000000, 0.000000000, NaN, 0.000000000, INVALID);
|
||||
test_fmodf(Infinity, 0.000000000, NaN, 0.000000000, INVALID);
|
||||
test_fmodf(-Infinity, 0.000000000, NaN, 0.000000000, INVALID);
|
||||
test_fmodf(NaN, 0.000000000, NaN, 0.000000000, 0);
|
||||
test_fmodf(-1.000000000, -0.000000000, NaN, 0.000000000, INVALID);
|
||||
test_fmodf(Infinity, -0.000000000, NaN, 0.000000000, INVALID);
|
||||
test_fmodf(-Infinity, -0.000000000, NaN, 0.000000000, INVALID);
|
||||
test_fmodf(NaN, -0.000000000, NaN, 0.000000000, 0);
|
||||
test_fmodf(Infinity, 2.000000000, NaN, 0.000000000, INVALID);
|
||||
test_fmodf(Infinity, -0.5000000000, NaN, 0.000000000, INVALID);
|
||||
test_fmodf(Infinity, NaN, NaN, 0.000000000, 0);
|
||||
test_fmodf(-Infinity, 2.000000000, NaN, 0.000000000, INVALID);
|
||||
test_fmodf(-Infinity, -0.5000000000, NaN, 0.000000000, INVALID);
|
||||
test_fmodf(-Infinity, NaN, NaN, 0.000000000, 0);
|
||||
test_fmodf(NaN, NaN, NaN, 0.000000000, 0);
|
||||
test_fmodf(1.000000000, NaN, NaN, 0.000000000, 0);
|
||||
test_fmodf(-1.000000000, NaN, NaN, 0.000000000, 0);
|
||||
test_fmodf(1.000000000, Infinity, 1.000000000, 0.000000000, 0);
|
||||
test_fmodf(-1.000000000, Infinity, -1.000000000, 0.000000000, 0);
|
||||
test_fmodf(Infinity, Infinity, NaN, 0.000000000, INVALID);
|
||||
test_fmodf(-Infinity, Infinity, NaN, 0.000000000, INVALID);
|
||||
test_fmodf(1.000000000, -Infinity, 1.000000000, 0.000000000, 0);
|
||||
test_fmodf(-1.000000000, -Infinity, -1.000000000, 0.000000000, 0);
|
||||
test_fmodf(Infinity, -Infinity, NaN, 0.000000000, INVALID);
|
||||
test_fmodf(-Infinity, -Infinity, NaN, 0.000000000, INVALID);
|
||||
test_fmodf(1.750000000, 0.5000000000, 0.2500000000, 0.000000000, 0);
|
||||
test_fmodf(-1.750000000, 0.5000000000, -0.2500000000, 0.000000000, 0);
|
||||
test_fmodf(1.750000000, -0.5000000000, 0.2500000000, 0.000000000, 0);
|
||||
test_fmodf(-1.750000000, -0.5000000000, -0.2500000000, 0.000000000, 0);
|
||||
|
||||
// ================================ Math.log ================================
|
||||
|
||||
function Math_log(value: f64, expected: f64, error: f64, flags: i32): void {
|
||||
function test_log(value: f64, expected: f64, error: f64, flags: i32): void {
|
||||
check<f64>(Math.log(value), expected, error, flags);
|
||||
check<f64>(JSMath.log(value), expected, error, flags);
|
||||
}
|
||||
|
||||
// sanity
|
||||
Math_log(-8.06684839057968084, NaN, 0.00000000000000000, INVALID);
|
||||
Math_log(4.34523984933830487, 1.46908095842243225, -0.341253340244293213, INEXACT);
|
||||
Math_log(-8.38143342755524934, NaN, 0.00000000000000000, INVALID);
|
||||
Math_log(-6.53167358191348413, NaN, 0.00000000000000000, INVALID);
|
||||
Math_log(9.26705696697258574, 2.22646584987956153, 0.363811403512954712, INEXACT);
|
||||
Math_log(0.661985898099504477, -0.412511025236513673, -0.291087478399276733, INEXACT);
|
||||
Math_log(-0.406603922385355310, NaN, 0.00000000000000000, INVALID);
|
||||
Math_log(0.561759746220724110, -0.576681018319586181, -0.109831996262073517, INEXACT);
|
||||
Math_log(0.774152296591303690, -0.255986659126386518, -0.0579900443553924561, INEXACT);
|
||||
Math_log(-0.678763702639402444, NaN, 0.00000000000000000, INVALID);
|
||||
test_log(-8.06684839057968084, NaN, 0.00000000000000000, INVALID);
|
||||
test_log(4.34523984933830487, 1.46908095842243225, -0.341253340244293213, INEXACT);
|
||||
test_log(-8.38143342755524934, NaN, 0.00000000000000000, INVALID);
|
||||
test_log(-6.53167358191348413, NaN, 0.00000000000000000, INVALID);
|
||||
test_log(9.26705696697258574, 2.22646584987956153, 0.363811403512954712, INEXACT);
|
||||
test_log(0.661985898099504477, -0.412511025236513673, -0.291087478399276733, INEXACT);
|
||||
test_log(-0.406603922385355310, NaN, 0.00000000000000000, INVALID);
|
||||
test_log(0.561759746220724110, -0.576681018319586181, -0.109831996262073517, INEXACT);
|
||||
test_log(0.774152296591303690, -0.255986659126386518, -0.0579900443553924561, INEXACT);
|
||||
test_log(-0.678763702639402444, NaN, 0.00000000000000000, INVALID);
|
||||
|
||||
// special
|
||||
Math_log(0.00000000000000000, -Infinity, 0.00000000000000000, DIVBYZERO);
|
||||
Math_log(-0.00000000000000000, -Infinity, 0.00000000000000000, DIVBYZERO);
|
||||
Math_log(-7.88860905221011805e-31, NaN, 0.00000000000000000, INVALID);
|
||||
Math_log(1.00000000000000000, 0.00000000000000000, 0.00000000000000000, 0);
|
||||
Math_log(-1.00000000000000000, NaN, 0.00000000000000000, INVALID);
|
||||
Math_log(Infinity, Infinity, 0.00000000000000000, 0);
|
||||
Math_log(-Infinity, NaN, 0.00000000000000000, INVALID);
|
||||
Math_log(NaN, NaN, 0.00000000000000000, 0);
|
||||
test_log(0.00000000000000000, -Infinity, 0.00000000000000000, DIVBYZERO);
|
||||
test_log(-0.00000000000000000, -Infinity, 0.00000000000000000, DIVBYZERO);
|
||||
test_log(-7.88860905221011805e-31, NaN, 0.00000000000000000, INVALID);
|
||||
test_log(1.00000000000000000, 0.00000000000000000, 0.00000000000000000, 0);
|
||||
test_log(-1.00000000000000000, NaN, 0.00000000000000000, INVALID);
|
||||
test_log(Infinity, Infinity, 0.00000000000000000, 0);
|
||||
test_log(-Infinity, NaN, 0.00000000000000000, INVALID);
|
||||
test_log(NaN, NaN, 0.00000000000000000, 0);
|
||||
|
||||
// ================================ Mathf.log ================================
|
||||
|
||||
function Mathf_log(value: f32, expected: f32, error: f32, flags: i32): void {
|
||||
function test_logf(value: f32, expected: f32, error: f32, flags: i32): void {
|
||||
check<f32>(Mathf.log(value), expected, error, flags);
|
||||
}
|
||||
|
||||
// sanity
|
||||
Mathf_log(0.000000000, -Infinity, 0.000000000, DIVBYZERO);
|
||||
Mathf_log(-0.000000000, -Infinity, 0.000000000, DIVBYZERO);
|
||||
Mathf_log(-7.888609052e-31, NaN, 0.000000000, INVALID);
|
||||
Mathf_log(1.000000000, 0.000000000, 0.000000000, 0);
|
||||
Mathf_log(-1.000000000, NaN, 0.000000000, INVALID);
|
||||
Mathf_log(Infinity, Infinity, 0.000000000, 0);
|
||||
Mathf_log(-Infinity, NaN, 0.000000000, INVALID);
|
||||
Mathf_log(NaN, NaN, 0.000000000, 0);
|
||||
test_logf(0.000000000, -Infinity, 0.000000000, DIVBYZERO);
|
||||
test_logf(-0.000000000, -Infinity, 0.000000000, DIVBYZERO);
|
||||
test_logf(-7.888609052e-31, NaN, 0.000000000, INVALID);
|
||||
test_logf(1.000000000, 0.000000000, 0.000000000, 0);
|
||||
test_logf(-1.000000000, NaN, 0.000000000, INVALID);
|
||||
test_logf(Infinity, Infinity, 0.000000000, 0);
|
||||
test_logf(-Infinity, NaN, 0.000000000, INVALID);
|
||||
test_logf(NaN, NaN, 0.000000000, 0);
|
||||
|
||||
// special
|
||||
Mathf_log(0.000000000, -Infinity, 0.000000000, DIVBYZERO);
|
||||
Mathf_log(-0.000000000, -Infinity, 0.000000000, DIVBYZERO);
|
||||
Mathf_log(-7.888609052e-31, NaN, 0.000000000, INVALID);
|
||||
Mathf_log(1.000000000, 0.000000000, 0.000000000, 0);
|
||||
Mathf_log(-1.000000000, NaN, 0.000000000, INVALID);
|
||||
Mathf_log(Infinity, Infinity, 0.000000000, 0);
|
||||
Mathf_log(-Infinity, NaN, 0.000000000, INVALID);
|
||||
Mathf_log(NaN, NaN, 0.000000000, 0);
|
||||
test_logf(0.000000000, -Infinity, 0.000000000, DIVBYZERO);
|
||||
test_logf(-0.000000000, -Infinity, 0.000000000, DIVBYZERO);
|
||||
test_logf(-7.888609052e-31, NaN, 0.000000000, INVALID);
|
||||
test_logf(1.000000000, 0.000000000, 0.000000000, 0);
|
||||
test_logf(-1.000000000, NaN, 0.000000000, INVALID);
|
||||
test_logf(Infinity, Infinity, 0.000000000, 0);
|
||||
test_logf(-Infinity, NaN, 0.000000000, INVALID);
|
||||
test_logf(NaN, NaN, 0.000000000, 0);
|
||||
|
||||
// ================================ Math.exp ================================
|
||||
|
||||
function Math_exp(value: f64, expected: f64, error: f64, flags: i32): void {
|
||||
function test_exp(value: f64, expected: f64, error: f64, flags: i32): void {
|
||||
check<f64>(Math.exp(value), expected, error, flags);
|
||||
check<f64>(JSMath.exp(value), expected, error, flags);
|
||||
}
|
||||
|
||||
// sanity
|
||||
Math_exp(-8.06684839057968084, 0.000313770606816174511, -0.259919732809066772, INEXACT);
|
||||
Math_exp(4.34523984933830487, 77.1105301711214111, -0.0279267579317092896, INEXACT);
|
||||
Math_exp(-8.38143342755524934, 0.000229081338491632304, -0.249743342399597168, INEXACT);
|
||||
Math_exp(-6.53167358191348413, 0.00145656612609315877, -0.481682240962982178, INEXACT);
|
||||
Math_exp(9.26705696697258574, 10583.5582455249933, 0.176967620849609375, INEXACT);
|
||||
Math_exp(0.661985898099504477, 1.93863845255719980, -0.496424645185470581, INEXACT);
|
||||
Math_exp(-0.406603922385355310, 0.665907889283802512, -0.106083184480667114, INEXACT);
|
||||
Math_exp(0.561759746220724110, 1.75375595186263111, -0.391621112823486328, INEXACT);
|
||||
Math_exp(0.774152296591303690, 2.16875288851292458, -0.299612581729888916, INEXACT);
|
||||
Math_exp(-0.678763702639402444, 0.507243708940284255, 0.472617387771606445, INEXACT);
|
||||
test_exp(-8.06684839057968084, 0.000313770606816174511, -0.259919732809066772, INEXACT);
|
||||
test_exp(4.34523984933830487, 77.1105301711214111, -0.0279267579317092896, INEXACT);
|
||||
test_exp(-8.38143342755524934, 0.000229081338491632304, -0.249743342399597168, INEXACT);
|
||||
test_exp(-6.53167358191348413, 0.00145656612609315877, -0.481682240962982178, INEXACT);
|
||||
test_exp(9.26705696697258574, 10583.5582455249933, 0.176967620849609375, INEXACT);
|
||||
test_exp(0.661985898099504477, 1.93863845255719980, -0.496424645185470581, INEXACT);
|
||||
test_exp(-0.406603922385355310, 0.665907889283802512, -0.106083184480667114, INEXACT);
|
||||
test_exp(0.561759746220724110, 1.75375595186263111, -0.391621112823486328, INEXACT);
|
||||
test_exp(0.774152296591303690, 2.16875288851292458, -0.299612581729888916, INEXACT);
|
||||
test_exp(-0.678763702639402444, 0.507243708940284255, 0.472617387771606445, INEXACT);
|
||||
|
||||
// special
|
||||
Math_exp(0.00000000000000000, 1.00000000000000000, 0.00000000000000000, 0);
|
||||
Math_exp(-0.00000000000000000, 1.00000000000000000, 0.00000000000000000, 0);
|
||||
Math_exp(1.00000000000000000, 2.71828182845904509, -0.325530737638473511, INEXACT);
|
||||
Math_exp(-1.00000000000000000, 0.367879441171442334, 0.223896518349647522, INEXACT);
|
||||
Math_exp(Infinity, Infinity, 0.00000000000000000, 0);
|
||||
Math_exp(-Infinity, 0.00000000000000000, 0.00000000000000000, 0);
|
||||
Math_exp(NaN, NaN, 0.00000000000000000, 0);
|
||||
Math_exp(1.03972148895263650, 2.82842915587641119, 0.188030809164047241, INEXACT);
|
||||
Math_exp(-1.03972148895263650, 0.353553136702178472, 0.252727240324020386, INEXACT);
|
||||
Math_exp(1.03972101211547852, 2.82842780717661224, -0.418413937091827393, INEXACT);
|
||||
Math_exp(1.03972148895263672, 2.82842915587641164, -0.226183772087097168, INEXACT);
|
||||
test_exp(0.00000000000000000, 1.00000000000000000, 0.00000000000000000, 0);
|
||||
test_exp(-0.00000000000000000, 1.00000000000000000, 0.00000000000000000, 0);
|
||||
test_exp(1.00000000000000000, 2.71828182845904509, -0.325530737638473511, INEXACT);
|
||||
test_exp(-1.00000000000000000, 0.367879441171442334, 0.223896518349647522, INEXACT);
|
||||
test_exp(Infinity, Infinity, 0.00000000000000000, 0);
|
||||
test_exp(-Infinity, 0.00000000000000000, 0.00000000000000000, 0);
|
||||
test_exp(NaN, NaN, 0.00000000000000000, 0);
|
||||
test_exp(1.03972148895263650, 2.82842915587641119, 0.188030809164047241, INEXACT);
|
||||
test_exp(-1.03972148895263650, 0.353553136702178472, 0.252727240324020386, INEXACT);
|
||||
test_exp(1.03972101211547852, 2.82842780717661224, -0.418413937091827393, INEXACT);
|
||||
test_exp(1.03972148895263672, 2.82842915587641164, -0.226183772087097168, INEXACT);
|
||||
|
||||
// ================================ Mathf.exp ================================
|
||||
|
||||
function Mathf_exp(value: f32, expected: f32, error: f32, flags: i32): void {
|
||||
function test_expf(value: f32, expected: f32, error: f32, flags: i32): void {
|
||||
check<f32>(Mathf.exp(value), expected, error, flags);
|
||||
}
|
||||
|
||||
// sanity
|
||||
Mathf_exp(-8.066848755, 0.0003137704916, -0.03019333631, INEXACT);
|
||||
Mathf_exp(4.345239639, 77.11051178, -0.2875460684, INEXACT);
|
||||
Mathf_exp(-8.381433487, 0.0002290813281, 0.2237040401, INEXACT);
|
||||
Mathf_exp(-6.531673431, 0.001456566388, 0.3646970391, INEXACT);
|
||||
Mathf_exp(9.267057419, 10583.56348, 0.4596210420, INEXACT);
|
||||
Mathf_exp(0.6619858742, 1.938638449, 0.3568260968, INEXACT);
|
||||
Mathf_exp(-0.4066039324, 0.6659078598, -0.3829499185, INEXACT);
|
||||
Mathf_exp(0.5617597699, 1.753756046, 0.4435549080, INEXACT);
|
||||
Mathf_exp(0.7741522789, 2.168752909, 0.2456246912, INEXACT);
|
||||
Mathf_exp(-0.6787636876, 0.5072436929, -0.3974292278, INEXACT);
|
||||
test_expf(-8.066848755, 0.0003137704916, -0.03019333631, INEXACT);
|
||||
test_expf(4.345239639, 77.11051178, -0.2875460684, INEXACT);
|
||||
test_expf(-8.381433487, 0.0002290813281, 0.2237040401, INEXACT);
|
||||
test_expf(-6.531673431, 0.001456566388, 0.3646970391, INEXACT);
|
||||
test_expf(9.267057419, 10583.56348, 0.4596210420, INEXACT);
|
||||
test_expf(0.6619858742, 1.938638449, 0.3568260968, INEXACT);
|
||||
test_expf(-0.4066039324, 0.6659078598, -0.3829499185, INEXACT);
|
||||
test_expf(0.5617597699, 1.753756046, 0.4435549080, INEXACT);
|
||||
test_expf(0.7741522789, 2.168752909, 0.2456246912, INEXACT);
|
||||
test_expf(-0.6787636876, 0.5072436929, -0.3974292278, INEXACT);
|
||||
|
||||
// special
|
||||
Mathf_exp(0.000000000, 1.000000000, 0.000000000, 0);
|
||||
Mathf_exp(-0.000000000, 1.000000000, 0.000000000, 0);
|
||||
Mathf_exp(1.000000000, 2.718281746, -0.3462330997, INEXACT);
|
||||
Mathf_exp(-1.000000000, 0.3678794503, 0.3070148528, INEXACT);
|
||||
Mathf_exp(Infinity, Infinity, 0.000000000, 0);
|
||||
Mathf_exp(-Infinity, 0.000000000, 0.000000000, 0);
|
||||
Mathf_exp(NaN, NaN, 0.000000000, 0);
|
||||
Mathf_exp(88.72283173, 3.402798519e+38, -0.09067153931, INEXACT);
|
||||
Mathf_exp(88.72283936, Infinity, 0.000000000, INEXACT|OVERFLOW);
|
||||
Mathf_exp(-103.9720764, 1.401298464e-45, 0.4999996722, INEXACT|UNDERFLOW);
|
||||
Mathf_exp(-103.9720840, 0.000000000, -0.4999965131, INEXACT|UNDERFLOW);
|
||||
Mathf_exp(0.3465735614, 1.414213538, 0.1392242163, INEXACT);
|
||||
Mathf_exp(0.3465735912, 1.414213538, -0.2143291682, INEXACT);
|
||||
Mathf_exp(0.3465736210, 1.414213657, 0.4321174324, INEXACT);
|
||||
test_expf(0.000000000, 1.000000000, 0.000000000, 0);
|
||||
test_expf(-0.000000000, 1.000000000, 0.000000000, 0);
|
||||
test_expf(1.000000000, 2.718281746, -0.3462330997, INEXACT);
|
||||
test_expf(-1.000000000, 0.3678794503, 0.3070148528, INEXACT);
|
||||
test_expf(Infinity, Infinity, 0.000000000, 0);
|
||||
test_expf(-Infinity, 0.000000000, 0.000000000, 0);
|
||||
test_expf(NaN, NaN, 0.000000000, 0);
|
||||
test_expf(88.72283173, 3.402798519e+38, -0.09067153931, INEXACT);
|
||||
test_expf(88.72283936, Infinity, 0.000000000, INEXACT|OVERFLOW);
|
||||
test_expf(-103.9720764, 1.401298464e-45, 0.4999996722, INEXACT|UNDERFLOW);
|
||||
test_expf(-103.9720840, 0.000000000, -0.4999965131, INEXACT|UNDERFLOW);
|
||||
test_expf(0.3465735614, 1.414213538, 0.1392242163, INEXACT);
|
||||
test_expf(0.3465735912, 1.414213538, -0.2143291682, INEXACT);
|
||||
test_expf(0.3465736210, 1.414213657, 0.4321174324, INEXACT);
|
||||
|
||||
// ================================ Math.pow ================================
|
||||
|
||||
function test_pow(left: f64, right: f64, expected: f64, error: f64, flags: i32): void {
|
||||
check<f64>(Math.pow(left, right), expected, error, flags);
|
||||
}
|
||||
|
||||
// sanity
|
||||
test_pow(-8.06684839057968084, 4.53566256067686879, NaN, 0.00000000000000000, INVALID);
|
||||
test_pow(4.34523984933830487, -8.88799136300345083, 0.00000213471188255872853, 0.325016021728515625, INEXACT);
|
||||
test_pow(-8.38143342755524934, -2.76360733737958819, NaN, 0.00000000000000000, INVALID);
|
||||
test_pow(-6.53167358191348413, 4.56753527684274374, NaN, 0.00000000000000000, INVALID);
|
||||
test_pow(9.26705696697258574, 4.81139208435979615, 44909.2994151296589, -0.266590803861618042, INEXACT);
|
||||
test_pow(-6.45004555606023633, 0.662071792337673881, NaN, 0.00000000000000000, INVALID);
|
||||
test_pow(7.85889025304169664, 0.0521545267500622481, 1.11351774134586523, -0.371686071157455444, INEXACT);
|
||||
test_pow(-0.792054511984895959, 7.67640268511753998, NaN, 0.00000000000000000, INVALID);
|
||||
test_pow(0.615702673197924044, 2.01190257903248026, 0.376907735213801831, 0.324733018875122070, INEXACT);
|
||||
test_pow(-0.558758682360915193, 0.0322398306026380407, NaN, 0.00000000000000000, INVALID);
|
||||
// special
|
||||
test_pow(0.00000000000000000, NaN, NaN, 0.00000000000000000, 0);
|
||||
test_pow(0.00000000000000000, Infinity, 0.00000000000000000, 0.00000000000000000, 0);
|
||||
test_pow(0.00000000000000000, 3.00000000000000000, 0.00000000000000000, 0.00000000000000000, 0);
|
||||
test_pow(0.00000000000000000, 2.00000000000000000, 0.00000000000000000, 0.00000000000000000, 0);
|
||||
test_pow(0.00000000000000000, 1.00000000000000000, 0.00000000000000000, 0.00000000000000000, 0);
|
||||
test_pow(0.00000000000000000, 0.500000000000000000, 0.00000000000000000, 0.00000000000000000, 0);
|
||||
test_pow(0.00000000000000000, 0.00000000000000000, 1.00000000000000000, 0.00000000000000000, 0);
|
||||
test_pow(0.00000000000000000, -0.00000000000000000, 1.00000000000000000, 0.00000000000000000, 0);
|
||||
test_pow(0.00000000000000000, -0.500000000000000000, Infinity, 0.00000000000000000, DIVBYZERO);
|
||||
test_pow(0.00000000000000000, -1.00000000000000000, Infinity, 0.00000000000000000, DIVBYZERO);
|
||||
test_pow(0.00000000000000000, -2.00000000000000000, Infinity, 0.00000000000000000, DIVBYZERO);
|
||||
test_pow(0.00000000000000000, -3.00000000000000000, Infinity, 0.00000000000000000, DIVBYZERO);
|
||||
test_pow(0.00000000000000000, -4.00000000000000000, Infinity, 0.00000000000000000, DIVBYZERO);
|
||||
test_pow(0.00000000000000000, -Infinity, Infinity, 0.00000000000000000, 0);
|
||||
test_pow(-0.00000000000000000, NaN, NaN, 0.00000000000000000, 0);
|
||||
test_pow(-0.00000000000000000, Infinity, 0.00000000000000000, 0.00000000000000000, 0);
|
||||
test_pow(-0.00000000000000000, 3.00000000000000000, -0.00000000000000000, 0.00000000000000000, 0);
|
||||
test_pow(-0.00000000000000000, 2.00000000000000000, 0.00000000000000000, 0.00000000000000000, 0);
|
||||
test_pow(-0.00000000000000000, 1.00000000000000000, -0.00000000000000000, 0.00000000000000000, 0);
|
||||
test_pow(-0.00000000000000000, 0.500000000000000000, 0.00000000000000000, 0.00000000000000000, 0);
|
||||
test_pow(-0.00000000000000000, 0.00000000000000000, 1.00000000000000000, 0.00000000000000000, 0);
|
||||
test_pow(-0.00000000000000000, -0.00000000000000000, 1.00000000000000000, 0.00000000000000000, 0);
|
||||
test_pow(-0.00000000000000000, -0.500000000000000000, Infinity, 0.00000000000000000, DIVBYZERO);
|
||||
test_pow(-0.00000000000000000, -1.00000000000000000, -Infinity, 0.00000000000000000, DIVBYZERO);
|
||||
test_pow(-0.00000000000000000, -2.00000000000000000, Infinity, 0.00000000000000000, DIVBYZERO);
|
||||
test_pow(-0.00000000000000000, -3.00000000000000000, -Infinity, 0.00000000000000000, DIVBYZERO);
|
||||
test_pow(-0.00000000000000000, -4.00000000000000000, Infinity, 0.00000000000000000, DIVBYZERO);
|
||||
test_pow(-0.00000000000000000, -Infinity, Infinity, 0.00000000000000000, 0);
|
||||
test_pow(NaN, 0.00000000000000000, 1.00000000000000000, 0.00000000000000000, 0);
|
||||
test_pow(Infinity, 0.00000000000000000, 1.00000000000000000, 0.00000000000000000, 0);
|
||||
test_pow(-Infinity, 0.00000000000000000, 1.00000000000000000, 0.00000000000000000, 0);
|
||||
test_pow(1.00000000000000000, 0.00000000000000000, 1.00000000000000000, 0.00000000000000000, 0);
|
||||
test_pow(-1.00000000000000000, 0.00000000000000000, 1.00000000000000000, 0.00000000000000000, 0);
|
||||
test_pow(-0.500000000000000000, 0.00000000000000000, 1.00000000000000000, 0.00000000000000000, 0);
|
||||
test_pow(NaN, -0.00000000000000000, 1.00000000000000000, 0.00000000000000000, 0);
|
||||
test_pow(Infinity, -0.00000000000000000, 1.00000000000000000, 0.00000000000000000, 0);
|
||||
test_pow(-Infinity, -0.00000000000000000, 1.00000000000000000, 0.00000000000000000, 0);
|
||||
test_pow(1.00000000000000000, -0.00000000000000000, 1.00000000000000000, 0.00000000000000000, 0);
|
||||
test_pow(-1.00000000000000000, -0.00000000000000000, 1.00000000000000000, 0.00000000000000000, 0);
|
||||
test_pow(-0.500000000000000000, -0.00000000000000000, 1.00000000000000000, 0.00000000000000000, 0);
|
||||
test_pow(-1.00000000000000000, NaN, NaN, 0.00000000000000000, 0);
|
||||
test_pow(-1.00000000000000000, Infinity, 1.00000000000000000, 0.00000000000000000, 0);
|
||||
test_pow(-1.00000000000000000, -Infinity, 1.00000000000000000, 0.00000000000000000, 0);
|
||||
test_pow(-1.00000000000000000, 2.00000000000000000, 1.00000000000000000, 0.00000000000000000, 0);
|
||||
test_pow(-1.00000000000000000, -1.00000000000000000, -1.00000000000000000, 0.00000000000000000, 0);
|
||||
test_pow(-1.00000000000000000, -2.00000000000000000, 1.00000000000000000, 0.00000000000000000, 0);
|
||||
test_pow(-1.00000000000000000, -3.00000000000000000, -1.00000000000000000, 0.00000000000000000, 0);
|
||||
test_pow(-1.00000000000000000, 0.500000000000000000, NaN, 0.00000000000000000, INVALID);
|
||||
test_pow(1.00000000000000000, NaN, 1.00000000000000000, 0.00000000000000000, 0);
|
||||
test_pow(1.00000000000000000, Infinity, 1.00000000000000000, 0.00000000000000000, 0);
|
||||
test_pow(1.00000000000000000, -Infinity, 1.00000000000000000, 0.00000000000000000, 0);
|
||||
test_pow(1.00000000000000000, 3.00000000000000000, 1.00000000000000000, 0.00000000000000000, 0);
|
||||
test_pow(1.00000000000000000, 0.500000000000000000, 1.00000000000000000, 0.00000000000000000, 0);
|
||||
test_pow(1.00000000000000000, -0.500000000000000000, 1.00000000000000000, 0.00000000000000000, 0);
|
||||
test_pow(1.00000000000000000, -3.00000000000000000, 1.00000000000000000, 0.00000000000000000, 0);
|
||||
test_pow(-0.500000000000000000, 0.500000000000000000, NaN, 0.00000000000000000, INVALID);
|
||||
test_pow(-0.500000000000000000, 1.50000000000000000, NaN, 0.00000000000000000, INVALID);
|
||||
test_pow(-0.500000000000000000, 2.00000000000000000, 0.250000000000000000, 0.00000000000000000, 0);
|
||||
test_pow(-0.500000000000000000, 3.00000000000000000, -0.125000000000000000, 0.00000000000000000, 0);
|
||||
test_pow(-0.500000000000000000, Infinity, 0.00000000000000000, 0.00000000000000000, 0);
|
||||
test_pow(-0.500000000000000000, -Infinity, Infinity, 0.00000000000000000, 0);
|
||||
test_pow(-0.500000000000000000, NaN, NaN, 0.00000000000000000, 0);
|
||||
test_pow(0.500000000000000000, Infinity, 0.00000000000000000, 0.00000000000000000, 0);
|
||||
test_pow(0.500000000000000000, -Infinity, Infinity, 0.00000000000000000, 0);
|
||||
test_pow(0.500000000000000000, NaN, NaN, 0.00000000000000000, 0);
|
||||
test_pow(1.50000000000000000, Infinity, Infinity, 0.00000000000000000, 0);
|
||||
test_pow(1.50000000000000000, -Infinity, 0.00000000000000000, 0.00000000000000000, 0);
|
||||
test_pow(1.50000000000000000, NaN, NaN, 0.00000000000000000, 0);
|
||||
test_pow(Infinity, NaN, NaN, 0.00000000000000000, 0);
|
||||
test_pow(Infinity, Infinity, Infinity, 0.00000000000000000, 0);
|
||||
test_pow(Infinity, -Infinity, 0.00000000000000000, 0.00000000000000000, 0);
|
||||
test_pow(Infinity, 3.00000000000000000, Infinity, 0.00000000000000000, 0);
|
||||
test_pow(Infinity, 2.00000000000000000, Infinity, 0.00000000000000000, 0);
|
||||
test_pow(Infinity, 1.00000000000000000, Infinity, 0.00000000000000000, 0);
|
||||
test_pow(Infinity, 0.500000000000000000, Infinity, 0.00000000000000000, 0);
|
||||
test_pow(Infinity, -0.500000000000000000, 0.00000000000000000, 0.00000000000000000, 0);
|
||||
test_pow(Infinity, -1.00000000000000000, 0.00000000000000000, 0.00000000000000000, 0);
|
||||
test_pow(Infinity, -2.00000000000000000, 0.00000000000000000, 0.00000000000000000, 0);
|
||||
test_pow(-Infinity, NaN, NaN, 0.00000000000000000, 0);
|
||||
test_pow(-Infinity, Infinity, Infinity, 0.00000000000000000, 0);
|
||||
test_pow(-Infinity, -Infinity, 0.00000000000000000, 0.00000000000000000, 0);
|
||||
test_pow(-Infinity, 3.00000000000000000, -Infinity, 0.00000000000000000, 0);
|
||||
test_pow(-Infinity, 2.00000000000000000, Infinity, 0.00000000000000000, 0);
|
||||
test_pow(-Infinity, 1.00000000000000000, -Infinity, 0.00000000000000000, 0);
|
||||
test_pow(-Infinity, 0.500000000000000000, Infinity, 0.00000000000000000, 0);
|
||||
test_pow(-Infinity, -0.500000000000000000, 0.00000000000000000, 0.00000000000000000, 0);
|
||||
test_pow(-Infinity, -1.00000000000000000, -0.00000000000000000, 0.00000000000000000, 0);
|
||||
test_pow(-Infinity, -2.00000000000000000, 0.00000000000000000, 0.00000000000000000, 0);
|
||||
test_pow(NaN, 1.00000000000000000, NaN, 0.00000000000000000, 0);
|
||||
test_pow(NaN, -1.00000000000000000, NaN, 0.00000000000000000, 0);
|
||||
test_pow(-2.00000000000000000, 1.00000000000000000, -2.00000000000000000, 0.00000000000000000, 0);
|
||||
test_pow(-2.00000000000000000, -1.00000000000000000, -0.500000000000000000, 0.00000000000000000, 0);
|
||||
|
||||
// ================================ Mathf.pow ================================
|
||||
|
||||
function test_powf(left: f32, right: f32, expected: f32, error: f32, flags: i32): void {
|
||||
check<f32>(Mathf.pow(left, right), expected, error, flags);
|
||||
}
|
||||
|
||||
// sanity
|
||||
test_powf(-8.066848755, 4.535662651, NaN, 0.000000000, INVALID);
|
||||
test_powf(4.345239639, -8.887990952, 0.000002134714123, 0.1436440796, INEXACT);
|
||||
test_powf(-8.381433487, -2.763607264, NaN, 0.000000000, INVALID);
|
||||
test_powf(-6.531673431, 4.567535400, NaN, 0.000000000, INVALID);
|
||||
test_powf(9.267057419, 4.811392307, 44909.33203, -0.05356409028, INEXACT);
|
||||
test_powf(-6.450045586, 0.6620717645, NaN, 0.000000000, INVALID);
|
||||
test_powf(7.858890057, 0.05215452611, 1.113517761, 0.1912208945, INEXACT);
|
||||
test_powf(-0.7920545340, 7.676402569, NaN, 0.000000000, INVALID);
|
||||
test_powf(0.6157026887, 2.011902571, 0.3769077659, 0.3371490538, INEXACT);
|
||||
test_powf(-0.5587586761, 0.03223983198, NaN, 0.000000000, INVALID);
|
||||
// special
|
||||
test_powf(0.000000000, NaN, NaN, 0.000000000, 0);
|
||||
test_powf(0.000000000, Infinity, 0.000000000, 0.000000000, 0);
|
||||
test_powf(0.000000000, 3.000000000, 0.000000000, 0.000000000, 0);
|
||||
test_powf(0.000000000, 2.000000000, 0.000000000, 0.000000000, 0);
|
||||
test_powf(0.000000000, 1.000000000, 0.000000000, 0.000000000, 0);
|
||||
test_powf(0.000000000, 0.5000000000, 0.000000000, 0.000000000, 0);
|
||||
test_powf(0.000000000, 0.000000000, 1.000000000, 0.000000000, 0);
|
||||
test_powf(0.000000000, -0.000000000, 1.000000000, 0.000000000, 0);
|
||||
test_powf(0.000000000, -0.5000000000, Infinity, 0.000000000, DIVBYZERO);
|
||||
test_powf(0.000000000, -1.000000000, Infinity, 0.000000000, DIVBYZERO);
|
||||
test_powf(0.000000000, -2.000000000, Infinity, 0.000000000, DIVBYZERO);
|
||||
test_powf(0.000000000, -3.000000000, Infinity, 0.000000000, DIVBYZERO);
|
||||
test_powf(0.000000000, -4.000000000, Infinity, 0.000000000, DIVBYZERO);
|
||||
test_powf(0.000000000, -Infinity, Infinity, 0.000000000, 0);
|
||||
test_powf(-0.000000000, NaN, NaN, 0.000000000, 0);
|
||||
test_powf(-0.000000000, Infinity, 0.000000000, 0.000000000, 0);
|
||||
test_powf(-0.000000000, 3.000000000, -0.000000000, 0.000000000, 0);
|
||||
test_powf(-0.000000000, 2.000000000, 0.000000000, 0.000000000, 0);
|
||||
test_powf(-0.000000000, 1.000000000, -0.000000000, 0.000000000, 0);
|
||||
test_powf(-0.000000000, 0.5000000000, 0.000000000, 0.000000000, 0);
|
||||
test_powf(-0.000000000, 0.000000000, 1.000000000, 0.000000000, 0);
|
||||
test_powf(-0.000000000, -0.000000000, 1.000000000, 0.000000000, 0);
|
||||
test_powf(-0.000000000, -0.5000000000, Infinity, 0.000000000, DIVBYZERO);
|
||||
test_powf(-0.000000000, -1.000000000, -Infinity, 0.000000000, DIVBYZERO);
|
||||
test_powf(-0.000000000, -2.000000000, Infinity, 0.000000000, DIVBYZERO);
|
||||
test_powf(-0.000000000, -3.000000000, -Infinity, 0.000000000, DIVBYZERO);
|
||||
test_powf(-0.000000000, -4.000000000, Infinity, 0.000000000, DIVBYZERO);
|
||||
test_powf(-0.000000000, -Infinity, Infinity, 0.000000000, 0);
|
||||
test_powf(NaN, 0.000000000, 1.000000000, 0.000000000, 0);
|
||||
test_powf(Infinity, 0.000000000, 1.000000000, 0.000000000, 0);
|
||||
test_powf(-Infinity, 0.000000000, 1.000000000, 0.000000000, 0);
|
||||
test_powf(1.000000000, 0.000000000, 1.000000000, 0.000000000, 0);
|
||||
test_powf(-1.000000000, 0.000000000, 1.000000000, 0.000000000, 0);
|
||||
test_powf(-0.5000000000, 0.000000000, 1.000000000, 0.000000000, 0);
|
||||
test_powf(NaN, -0.000000000, 1.000000000, 0.000000000, 0);
|
||||
test_powf(Infinity, -0.000000000, 1.000000000, 0.000000000, 0);
|
||||
test_powf(-Infinity, -0.000000000, 1.000000000, 0.000000000, 0);
|
||||
test_powf(1.000000000, -0.000000000, 1.000000000, 0.000000000, 0);
|
||||
test_powf(-1.000000000, -0.000000000, 1.000000000, 0.000000000, 0);
|
||||
test_powf(-0.5000000000, -0.000000000, 1.000000000, 0.000000000, 0);
|
||||
test_powf(-1.000000000, NaN, NaN, 0.000000000, 0);
|
||||
test_powf(-1.000000000, Infinity, 1.000000000, 0.000000000, 0);
|
||||
test_powf(-1.000000000, -Infinity, 1.000000000, 0.000000000, 0);
|
||||
test_powf(-1.000000000, 2.000000000, 1.000000000, 0.000000000, 0);
|
||||
test_powf(-1.000000000, -1.000000000, -1.000000000, 0.000000000, 0);
|
||||
test_powf(-1.000000000, -2.000000000, 1.000000000, 0.000000000, 0);
|
||||
test_powf(-1.000000000, -3.000000000, -1.000000000, 0.000000000, 0);
|
||||
test_powf(-1.000000000, 0.5000000000, NaN, 0.000000000, INVALID);
|
||||
test_powf(1.000000000, NaN, 1.000000000, 0.000000000, 0);
|
||||
test_powf(1.000000000, Infinity, 1.000000000, 0.000000000, 0);
|
||||
test_powf(1.000000000, -Infinity, 1.000000000, 0.000000000, 0);
|
||||
test_powf(1.000000000, 3.000000000, 1.000000000, 0.000000000, 0);
|
||||
test_powf(1.000000000, 0.5000000000, 1.000000000, 0.000000000, 0);
|
||||
test_powf(1.000000000, -0.5000000000, 1.000000000, 0.000000000, 0);
|
||||
test_powf(1.000000000, -3.000000000, 1.000000000, 0.000000000, 0);
|
||||
test_powf(-0.5000000000, 0.5000000000, NaN, 0.000000000, INVALID);
|
||||
test_powf(-0.5000000000, 1.500000000, NaN, 0.000000000, INVALID);
|
||||
test_powf(-0.5000000000, 2.000000000, 0.2500000000, 0.000000000, 0);
|
||||
test_powf(-0.5000000000, 3.000000000, -0.1250000000, 0.000000000, 0);
|
||||
test_powf(-0.5000000000, Infinity, 0.000000000, 0.000000000, 0);
|
||||
test_powf(-0.5000000000, -Infinity, Infinity, 0.000000000, 0);
|
||||
test_powf(-0.5000000000, NaN, NaN, 0.000000000, 0);
|
||||
test_powf(0.5000000000, Infinity, 0.000000000, 0.000000000, 0);
|
||||
test_powf(0.5000000000, -Infinity, Infinity, 0.000000000, 0);
|
||||
test_powf(0.5000000000, NaN, NaN, 0.000000000, 0);
|
||||
test_powf(1.500000000, Infinity, Infinity, 0.000000000, 0);
|
||||
test_powf(1.500000000, -Infinity, 0.000000000, 0.000000000, 0);
|
||||
test_powf(1.500000000, NaN, NaN, 0.000000000, 0);
|
||||
test_powf(Infinity, NaN, NaN, 0.000000000, 0);
|
||||
test_powf(Infinity, Infinity, Infinity, 0.000000000, 0);
|
||||
test_powf(Infinity, -Infinity, 0.000000000, 0.000000000, 0);
|
||||
test_powf(Infinity, 3.000000000, Infinity, 0.000000000, 0);
|
||||
test_powf(Infinity, 2.000000000, Infinity, 0.000000000, 0);
|
||||
test_powf(Infinity, 1.000000000, Infinity, 0.000000000, 0);
|
||||
test_powf(Infinity, 0.5000000000, Infinity, 0.000000000, 0);
|
||||
test_powf(Infinity, -0.5000000000, 0.000000000, 0.000000000, 0);
|
||||
test_powf(Infinity, -1.000000000, 0.000000000, 0.000000000, 0);
|
||||
test_powf(Infinity, -2.000000000, 0.000000000, 0.000000000, 0);
|
||||
test_powf(-Infinity, NaN, NaN, 0.000000000, 0);
|
||||
test_powf(-Infinity, Infinity, Infinity, 0.000000000, 0);
|
||||
test_powf(-Infinity, -Infinity, 0.000000000, 0.000000000, 0);
|
||||
test_powf(-Infinity, 3.000000000, -Infinity, 0.000000000, 0);
|
||||
test_powf(-Infinity, 2.000000000, Infinity, 0.000000000, 0);
|
||||
test_powf(-Infinity, 1.000000000, -Infinity, 0.000000000, 0);
|
||||
test_powf(-Infinity, 0.5000000000, Infinity, 0.000000000, 0);
|
||||
test_powf(-Infinity, -0.5000000000, 0.000000000, 0.000000000, 0);
|
||||
test_powf(-Infinity, -1.000000000, -0.000000000, 0.000000000, 0);
|
||||
test_powf(-Infinity, -2.000000000, 0.000000000, 0.000000000, 0);
|
||||
test_powf(NaN, 1.000000000, NaN, 0.000000000, 0);
|
||||
test_powf(NaN, -1.000000000, NaN, 0.000000000, 0);
|
||||
test_powf(-2.000000000, 1.000000000, -2.000000000, 0.000000000, 0);
|
||||
test_powf(-2.000000000, -1.000000000, -0.5000000000, 0.000000000, 0);
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -1040,9 +1040,7 @@
|
||||
)
|
||||
(i32.and
|
||||
(get_local $0)
|
||||
(i32.wrap/i64
|
||||
(i64.const 4294901760)
|
||||
)
|
||||
(i32.const -65536)
|
||||
)
|
||||
)
|
||||
)
|
||||
@ -1125,13 +1123,9 @@
|
||||
(i32.eqz
|
||||
(i32.eq
|
||||
(call "$(lib)/polyfills/bswap<i32>"
|
||||
(i32.wrap/i64
|
||||
(i64.const 2864434397)
|
||||
)
|
||||
)
|
||||
(i32.wrap/i64
|
||||
(i64.const 3721182122)
|
||||
(i32.const -1430532899)
|
||||
)
|
||||
(i32.const -573785174)
|
||||
)
|
||||
)
|
||||
(block
|
||||
@ -1293,13 +1287,9 @@
|
||||
(i32.eqz
|
||||
(i32.eq
|
||||
(call "$(lib)/polyfills/bswap16<i32>"
|
||||
(i32.wrap/i64
|
||||
(i64.const 4287146683)
|
||||
)
|
||||
)
|
||||
(i32.wrap/i64
|
||||
(i64.const 4287151018)
|
||||
(i32.const -7820613)
|
||||
)
|
||||
(i32.const -7816278)
|
||||
)
|
||||
)
|
||||
(block
|
||||
|
12
tslint.json
12
tslint.json
@ -21,6 +21,18 @@
|
||||
},
|
||||
"semicolon": {
|
||||
"options": ["always"]
|
||||
},
|
||||
"whitespace": {
|
||||
"options": [
|
||||
"check-branch",
|
||||
"check-decl",
|
||||
"check-operator",
|
||||
"check-module",
|
||||
"check-rest-spread",
|
||||
"check-type",
|
||||
"check-type-operator",
|
||||
"check-preblock"
|
||||
]
|
||||
}
|
||||
},
|
||||
"jsRules": {
|
||||
|
Loading…
x
Reference in New Issue
Block a user