Debian Codegraph @

js/src/tests/test262/built-ins/Math/fround/ties.js

raw
1 // Copyright (C) 2019 Tiancheng "Timothy" Gu. All rights reserved.
2 // This code is governed by the BSD license found in the LICENSE file.
3 /*---
4 esid: sec-math.fround
5 description: Math.fround should use roundTiesToEven for conversion to binary32.
6 ---*/
7
8 // We test five values against Math.fround, with their binary64 representation
9 // shown:
10 // a0 := 1.0 = 0x1p+0
11 // a1 := 1.0000000596046448 = 0x1.000001p+0
12 // a2 := 1.0000001192092896 = 0x1.000002p+0
13 // a3 := 1.0000001788139343 = 0x1.000003p+0
14 // a4 := 1.000000238418579 = 0x1.000004p+0
15 // a5 := 1.0000002980232239 = 0x1.000005p+0
16 // a6 := 1.0000003576278687 = 0x1.000006p+0
17 // (Note: they are separated by 2 ** -24.)
18 //
19 // a0, a2, a4, and a6 are all representable exactly in binary32; however, while
20 // a0 and a4 have even mantissas in binary32, a2 and a6 have an odd mantissa
21 // when represented in that way.
22 //
23 // a1 is exactly halfway between a0 and a2, a3 between a2 and a4, and a5
24 // between a4 and a6. By roundTiesToEven, Math.fround should favor a0 and a4
25 // over a2 when they are equally close, and a4 over a6 when they are equally
26 // close.
27
28 var a0 = 1.0;
29 var a1 = 1.0000000596046448;
30 var a2 = 1.0000001192092896;
31 var a3 = 1.0000001788139343;
32 var a4 = 1.000000238418579;
33 var a5 = 1.0000002980232239;
34 var a6 = 1.0000003576278687;
35
36 assert.sameValue(Math.fround(a0), a0, 'Math.fround(a0)');
37 assert.sameValue(Math.fround(a1), a0, 'Math.fround(a1)');
38 assert.sameValue(Math.fround(a2), a2, 'Math.fround(a2)');
39 assert.sameValue(Math.fround(a3), a4, 'Math.fround(a3)');
40 assert.sameValue(Math.fround(a4), a4, 'Math.fround(a4)');
41 assert.sameValue(Math.fround(a5), a4, 'Math.fround(a5)');
42 assert.sameValue(Math.fround(a6), a6, 'Math.fround(a6)');
43
44 assert.sameValue(Math.fround(-a0), -a0, 'Math.fround(-a0)');
45 assert.sameValue(Math.fround(-a1), -a0, 'Math.fround(-a1)');
46 assert.sameValue(Math.fround(-a2), -a2, 'Math.fround(-a2)');
47 assert.sameValue(Math.fround(-a3), -a4, 'Math.fround(-a3)');
48 assert.sameValue(Math.fround(-a4), -a4, 'Math.fround(-a4)');
49 assert.sameValue(Math.fround(-a5), -a4, 'Math.fround(-a5)');
50 assert.sameValue(Math.fround(-a6), -a6, 'Math.fround(-a6)');
51
52 reportCompare(0, 0);