Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
48 additions
and
4 deletions.
There are no files selected for viewing
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
QUnit.test('DataView.prototype.{ getFloat16, setFloat16 }', assert => { | ||
const { getFloat16, setFloat16 } = DataView.prototype; | ||
|
||
assert.isFunction(getFloat16); | ||
assert.arity(getFloat16, 1); | ||
assert.name(getFloat16, 'getFloat16'); | ||
|
||
assert.isFunction(setFloat16); | ||
assert.arity(setFloat16, 2); | ||
assert.name(setFloat16, 'setFloat16'); | ||
|
||
assert.same(new DataView(new ArrayBuffer(8)).setFloat16(0, 0), undefined, 'void'); | ||
|
||
function toString(it) { | ||
return it === 0 && 1 / it === -Infinity ? '-0' : it; | ||
} | ||
|
||
const data = [ | ||
[0b0000000000000000, 0], | ||
[0b1000000000000000, -0], | ||
[0b0011110000000000, 1], | ||
[0b1011110000000000, -1], | ||
[0b0100001001001000, 3.140625], | ||
[0b0000001000000000, 0.000030517578125], | ||
[0b0111101111111111, 65504], | ||
[0b1111101111111111, -65504], | ||
[0b0000000000000001, 2 ** -24], | ||
[0b1000000000000001, -(2 ** -24)], | ||
// [0b0111110000000001, NaN], <- what NaN should be used? | ||
[0b0111110000000000, Infinity], | ||
[0b1111110000000000, -Infinity], | ||
]; | ||
|
||
const buffer = new ArrayBuffer(2); | ||
const view = new DataView(buffer); | ||
|
||
for (const [bin, f16] of data) for (const LE of [false, true]) { | ||
view.setUint16(0, bin, LE); | ||
assert.same(view.getFloat16(0, LE), f16, `DataView.prototype.setUint16 + DataView.prototype.getFloat16, LE: ${ LE }, ${ toString(bin) } -> ${ toString(f16) }`); | ||
view.setFloat16(0, f16, LE); | ||
assert.same(view.getUint16(0, LE), bin, `DataView.prototype.setFloat16 + DataView.prototype.getUint16, LE: ${ LE }, ${ toString(f16) } -> ${ toString(bin) }`); | ||
assert.same(view.getFloat16(0, LE), f16, `DataView.prototype.setFloat16 + DataView.prototype.getFloat16, LE: ${ LE }, ${ toString(f16) }`); | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters