summaryrefslogtreecommitdiffstats
path: root/js/src/tests/test262/built-ins/DataView/prototype/getFloat16/toindex-byteoffset.js
blob: ae51364d35f331e3572179c3a41843650fe233ae (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
// |reftest| shell-option(--enable-float16array) skip-if(!this.hasOwnProperty('Float16Array')||!xulRuntime.shell) -- Float16Array is not enabled unconditionally, requires shell-options
// Copyright (C) 2024 Kevin Gibbons. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
esid: sec-dataview.prototype.getFloat16
description: >
  ToIndex conversions on byteOffset
features: [Float16Array, DataView.prototype.setUint8]
---*/

var buffer = new ArrayBuffer(6);
var sample = new DataView(buffer, 0);

sample.setUint8(0, 75);
sample.setUint8(1, 76);
sample.setUint8(2, 77);
sample.setUint8(3, 78);
sample.setUint8(4, 79);
sample.setUint8(5, 80);

var obj1 = {
  valueOf: function() {
    return 3;
  }
};

var obj2 = {
  toString: function() {
    return 2;
  }
};

assert.sameValue(sample.getFloat16(-0), 14.59375, "-0");
assert.sameValue(sample.getFloat16(obj1), 25.234375, "object's valueOf");
assert.sameValue(sample.getFloat16(obj2), 21.21875, "object's toString");
assert.sameValue(sample.getFloat16(""), 14.59375, "the Empty string");
assert.sameValue(sample.getFloat16("0"), 14.59375, "string '0'");
assert.sameValue(sample.getFloat16("2"), 21.21875, "string '2'");
assert.sameValue(sample.getFloat16(true), 17.203125, "true");
assert.sameValue(sample.getFloat16(false), 14.59375, "false");
assert.sameValue(sample.getFloat16(NaN), 14.59375, "NaN");
assert.sameValue(sample.getFloat16(null), 14.59375, "null");
assert.sameValue(sample.getFloat16(0.1), 14.59375, "0.1");
assert.sameValue(sample.getFloat16(0.9), 14.59375, "0.9");
assert.sameValue(sample.getFloat16(1.1), 17.203125, "1.1");
assert.sameValue(sample.getFloat16(1.9), 17.203125, "1.9");
assert.sameValue(sample.getFloat16(-0.1), 14.59375, "-0.1");
assert.sameValue(sample.getFloat16(-0.99999), 14.59375, "-0.99999");
assert.sameValue(sample.getFloat16(undefined), 14.59375, "undefined");
assert.sameValue(sample.getFloat16(), 14.59375, "no arg");

reportCompare(0, 0);