var f64 = new Float64Array(2); var f32 = new Float32Array(f64.buffer); var u8 = new Uint8Array(f64.buffer);
function assertSameBitPattern(from, to, offset) { for (let i = from; i < to; i++)
assertEq(u8[i], u8[i + offset], 'non equality in assertSameBitPattern');
}
// Check that custom NaN can't escape to normal JS, in non-testing mode.
f32[0] = NaN;
f32[0] = f32[0]; // Force canonicalization.
// There are two kinds of NaNs: signaling and quiet. Usually, the first bit of // the payload is used to indicate whether it is quiet (1 for quiet, 0 for // signaling). Most operations have to transform a signaling NaN into a quiet // NaN, which prevents some optimizations in WebAssembly.
// A float32 has 32 bits, 23 bits of them being reserved for the mantissa // (= NaN payload). var f32_qnan_code = '(f32.const nan:0x600000)'; var f32_snan_code = '(f32.const nan:0x200000)';
var f32_snan = '0x7fa00000'; var f32_qnan = '0x7fe00000';
// A float64 has 64 bits, 1 for the sign, 11 for the exponent, the rest for the // mantissa (payload). var f64_nan_base_high = 0x7ff00000;
var f64_snan_code = '(f64.const nan:0x4000000000000)'; var f64_qnan_code = '(f64.const nan:0xc000000000000)';
var f64_snan = '0x7ff4000000000000'; var f64_qnan = '0x7ffc000000000000';
// Wasm spec v1.1 section 4.3.3, sections "fadd" et seq and "NaN propagation": // If the input NaN is not canonical then the output may be any arithmetic NaN, // ie a quiet NaN with arbitrary payload.
;; An example where a signaling nan gets transformed into a quiet nan:
;; snan + 0.0 = qnan
(func $add (result f32) (f32.add ${f32_snan_code} (f32.const 0)))
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.