assertEq(Math.f16round(0 / 0), NaN);
assertEq(Math.f16round(1 / 0), Infinity);
assertEq(Math.f16round(-1 / 0), -Infinity);
}
} for (let i = 0; i < 2; ++i) fromConstant();
function fromInt32() { // ToFloat16(ToDouble(int32)) is folded to ToFloat16(int32).
// Int32 which are exactly representable as Float16. for (let i = 0; i <= 2048; ++i) {
let i32 = i | 0;
assertEq(Math.f16round(i32), i32);
}
// Int32 larger than 2048 are inexact.
assertEq(Math.f16round(2049), 2048);
// Int32 larger than 65519 are not representable.
assertEq(Math.f16round(65519), 65504);
// Int32 which are too large for Float16. for (let i = 0; i <= 100; ++i) {
let i32 = (i + 65520) | 0;
assertEq(Math.f16round(i32), Infinity);
}
} for (let i = 0; i < 2; ++i) fromInt32();
function fromFloat32() { // ToFloat16(ToDouble(float32)) is folded to ToFloat16(float32).
// Float32 which are exactly representable as Float16. for (let i = 0; i < 1024; ++i) {
let f32 = Math.fround(i + 0.5);
assertEq(Math.f16round(f32), f32);
}
// Float32 larger than 1023.5 are inexact.
assertEq(Math.f16round(1024.5), 1024);
// Float32 larger than 65519 are not representable.
assertEq(Math.f16round(65519.5), 65504);
// Float32 which are too large for Float16. for (let i = 0; i <= 100; ++i) {
let f32 = Math.fround(i + 65520.5);
assertEq(Math.f16round(f32), Infinity);
}
} for (let i = 0; i < 2; ++i) fromFloat32();
function fromLoadFloat16() { // ToFloat16(LoadFloat16(x)) is folded to LoadFloat16(x).
const nativeIsLittleEndian = new Uint8Array(new Uint16Array([1]).buffer)[0] === 1;
for (let i = 0; i < 200; ++i) {
let idx = i % f16.length;
let x = f16[idx];
let y = dv.getFloat16(idx * Float16Array.BYTES_PER_ELEMENT, nativeIsLittleEndian);
assertEq(x, y);
assertEq(Math.f16round(x), x);
assertEq(Math.f16round(y), y);
}
} for (let i = 0; i < 2; ++i) fromLoadFloat16();
Messung V0.5
¤ Dauer der Verarbeitung: 0.16 Sekunden
(vorverarbeitet)
¤
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.