diff options
author | Matt A. Tobin <mattatobin@localhost.localdomain> | 2018-02-02 04:16:08 -0500 |
---|---|---|
committer | Matt A. Tobin <mattatobin@localhost.localdomain> | 2018-02-02 04:16:08 -0500 |
commit | 5f8de423f190bbb79a62f804151bc24824fa32d8 (patch) | |
tree | 10027f336435511475e392454359edea8e25895d /js/src/tests/ecma_6/TypedArray/sort_snans.js | |
parent | 49ee0794b5d912db1f95dce6eb52d781dc210db5 (diff) | |
download | UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.gz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.lz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.xz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.zip |
Add m-esr52 at 52.6.0
Diffstat (limited to 'js/src/tests/ecma_6/TypedArray/sort_snans.js')
-rw-r--r-- | js/src/tests/ecma_6/TypedArray/sort_snans.js | 72 |
1 files changed, 72 insertions, 0 deletions
diff --git a/js/src/tests/ecma_6/TypedArray/sort_snans.js b/js/src/tests/ecma_6/TypedArray/sort_snans.js new file mode 100644 index 000000000..9e3ad1698 --- /dev/null +++ b/js/src/tests/ecma_6/TypedArray/sort_snans.js @@ -0,0 +1,72 @@ +// Ensure that signaling NaN's don't cause problems while sorting + +function getNaNArray(length) { + let a = []; + for (let i = 0; i < length; i++) + a.push(NaN); + return a; +} + +// Test every skipNth value in some range n, where start <= n <= end +// and start/stop should be 32-bit integers with bit patterns that +// form Float32 NaNs. +function testFloat32NaNRanges(start, end) { + let skipN = 10e3; + + // sample the space of possible NaNs to save time + let sampleSize = Math.floor((end - start)/ skipN); + + let NaNArray = new Float32Array(getNaNArray(sampleSize)); + let buffer = new ArrayBuffer(4 * sampleSize); + let uintView = new Uint32Array(buffer); + let floatView = new Float32Array(buffer); + + uintView[0] = start; + for (let i = 1; i < sampleSize; i++) { + uintView[i] = uintView[0] + (i * skipN); + } + + floatView.sort(); + assertDeepEq(floatView, NaNArray); +} + +// Test every skipNth value in some range n, where start <= n <= end +// and startHi, startLow and endHi, endLow should be 32-bit integers which, +// when combined (Hi + Low), form Float64 NaNs. +function testFloat64NaNRanges(startHi, startLow, endHi, endLow) { + let skipN = 10e6; + + let sampleSizeHi = Math.floor((endHi - startHi)/skipN); + let sampleSizeLow = Math.floor((endLow - startLow)/skipN); + + let NaNArray = new Float64Array(getNaNArray(sampleSizeHi + sampleSizeLow)); + let buffer = new ArrayBuffer(8 * (sampleSizeHi + sampleSizeLow)); + let uintView = new Uint32Array(buffer); + let floatView = new Float64Array(buffer); + + // Fill in all of the low bits first. + for (let i = 0; i <= sampleSizeLow; i++) { + uintView[i * 2] = startLow + (i * skipN); + uintView[(i * 2) + 1] = startHi; + } + + // Then the high bits. + for (let i = sampleSizeLow; i <= sampleSizeLow + sampleSizeHi; i++) { + uintView[i * 2] = endLow; + uintView[(i * 2) + 1] = startHi + ((i - sampleSizeLow) * skipN); + } + + floatView.sort(); + assertDeepEq(floatView, NaNArray); +} + +// Float32 Signaling NaN ranges +testFloat32NaNRanges(0x7F800001, 0x7FBFFFFF); +testFloat32NaNRanges(0xFF800001, 0xFFBFFFFF); + +// Float64 Signaling NaN ranges +testFloat64NaNRanges(0x7FF00000, 0x00000001, 0x7FF7FFFF, 0xFFFFFFFF); +testFloat64NaNRanges(0xFFF00000, 0x00000001, 0xFFF7FFFF, 0xFFFFFFFF); + +if (typeof reportCompare === "function") + reportCompare(true, true); |