// MSqrt function setupSqrt() {
f32[0] = 0;
f32[1] = 1;
f32[2] = 4;
f32[3] = -1;
f32[4] = Infinity;
f32[5] = NaN;
f32[6] = 13.37;
} function sqrt() { for(var i = 0; i < 7; ++i) { var sqrtf = Math.fround(Math.sqrt(f32[i])); var sqrtd = 1 + Math.sqrt(f32[i]) - 1; // force no float32 by chaining arith ops
assertEq( sqrtf, Math.fround(sqrtd) );
}
}
test(setupSqrt, sqrt);
// MMinMax function setupMinMax() {
f32[0] = -0;
f32[1] = 0;
f32[2] = 1;
f32[3] = 4;
f32[4] = -1;
f32[5] = Infinity;
f32[6] = NaN;
f32[7] = 13.37;
f32[8] = -Infinity;
f32[9] = Math.pow(2,31) - 1;
} function minMax() { for(var i = 0; i < 9; ++i) { for(var j = 0; j < 9; j++) { var minf = Math.fround(Math.min(f32[i], f32[j])); var mind = 1 / (1 / Math.min(f32[i], f32[j])); // force no float32 by chaining arith ops
assertFloat32(minf, true);
assertFloat32(mind, false);
assertEq( minf, Math.fround(mind) );
var maxf = Math.fround(Math.max(f32[i], f32[j])); var maxd = 1 / (1 / Math.max(f32[i], f32[j])); // force no float32 by chaining arith ops
assertFloat32(maxf, true);
assertFloat32(maxd, false);
assertEq( maxf, Math.fround(maxd) );
}
}
}
test(setupMinMax, minMax);
// MTruncateToInt32 // The only way to get a MTruncateToInt32 with a Float32 input is to use Math.imul function setupTruncateToInt32() {
f32[0] = -1;
f32[1] = 4;
f32[2] = 5.13;
} function truncateToInt32() {
assertEq( Math.imul(f32[0], f32[1]), Math.imul(-1, 4) );
assertEq( Math.imul(f32[1], f32[2]), Math.imul(4, 5) );
}
test(setupTruncateToInt32, truncateToInt32);
function setupBailoutToInt32() {
f32[0] = .5;
} function testBailoutToInt32() {
assertEq(typeof str[f32[0]], 'undefined');
}
test(setupBailoutToInt32, testBailoutToInt32);
// MMath (no trigo - see also testFloat32-trigo.js function assertNear(a, b) { var r = (a != a && b != b) || Math.abs(a-b) < 1e-1 || a === b; if (!r) {
print('Precision error: ');
print(new Error().stack);
print('Got', a, ', expected near', b);
assertEq(false, true);
}
}
function setupOtherMath() {
setupComp();
f32[8] = 4.2;
} function otherMath() { for (var i = 0; i < 9; ++i) {
assertNear(Math.fround(Math.exp(f32[i])), Math.exp(f32[i]));
assertNear(Math.fround(Math.log(f32[i])), Math.log(f32[i]));
}
};
test(setupOtherMath, otherMath);
function setupFloor() {
f32[0] = -5.5;
f32[1] = -0.5;
f32[2] = 0;
f32[3] = 1.5;
} function setupFloorDouble() {
f32[4] = NaN;
f32[5] = -0;
f32[6] = Infinity;
f32[7] = -Infinity;
f32[8] = Math.pow(2,31); // too big to fit into a int
} function testFloor() { for (var i = 0; i < 4; ++i) { var f = Math.floor(f32[i]);
assertFloat32(f, false); // f is an int32
var g = Math.floor(-0 + f32[i]);
assertFloat32(g, false);
assertEq(f, g);
}
} function testFloorDouble() { for (var i = 4; i < 9; ++i) { var f = Math.fround(Math.floor(f32[i]));
assertFloat32(f, true);
var g = Math.floor(-0 + f32[i]);
assertFloat32(g, false);
function setupRound() {
f32[0] = -5.5;
f32[1] = -0.6;
f32[2] = 1.5;
f32[3] = 1;
} function setupRoundDouble() {
f32[4] = NaN;
f32[5] = -0.49; // rounded to -0
f32[6] = Infinity;
f32[7] = -Infinity;
f32[8] = Math.pow(2,31); // too big to fit into a int
f32[9] = -0;
} function testRound() { for (var i = 0; i < 4; ++i) { var r32 = Math.round(f32[i]);
assertFloat32(r32, false); // r32 is an int32
var r64 = Math.round(-0 + f32[i]);
assertFloat32(r64, false);
assertEq(r32, r64);
}
} function testRoundDouble() { for (var i = 4; i < 10; ++i) { var r32 = Math.fround(Math.round(f32[i]));
assertFloat32(r32, true);
var r64 = Math.round(-0 + f32[i]);
assertFloat32(r64, false);
function setupCeil() {
f32[0] = -5.5;
f32[1] = -1.5;
f32[2] = 0;
f32[3] = 1.5;
} function setupCeilDouble() {
f32[4] = NaN;
f32[5] = -0;
f32[6] = Infinity;
f32[7] = -Infinity;
f32[8] = Math.pow(2,31); // too big to fit into a int
} function testCeil() { for(var i = 0; i < 2; ++i) { var f = Math.ceil(f32[i]);
assertFloat32(f, false);
var g = Math.ceil(-0 + f32[i]);
assertFloat32(g, false);
assertEq(f, g);
}
} function testCeilDouble() { for(var i = 4; i < 9; ++i) { var f = Math.fround(Math.ceil(f32[i]));
assertFloat32(f, true);
var g = Math.ceil(-0 + f32[i]);
assertFloat32(g, false);
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.