diff options
Diffstat (limited to 'js/src/tests/test262/built-ins/Math/fround')
11 files changed, 244 insertions, 0 deletions
diff --git a/js/src/tests/test262/built-ins/Math/fround/Math.fround_Infinity.js b/js/src/tests/test262/built-ins/Math/fround/Math.fround_Infinity.js new file mode 100644 index 0000000000..07230c73ee --- /dev/null +++ b/js/src/tests/test262/built-ins/Math/fround/Math.fround_Infinity.js @@ -0,0 +1,12 @@ +// Copyright (c) 2014 Ryan Lewis. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es6id: 20.2.2.17 +author: Ryan Lewis +description: Math.fround should return Infinity if called with Infinity. +---*/ + +assert.sameValue(Math.fround(Infinity), Infinity, 'Math.fround(Infinity)'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Math/fround/Math.fround_NaN.js b/js/src/tests/test262/built-ins/Math/fround/Math.fround_NaN.js new file mode 100644 index 0000000000..6b17546e51 --- /dev/null +++ b/js/src/tests/test262/built-ins/Math/fround/Math.fround_NaN.js @@ -0,0 +1,12 @@ +// Copyright (c) 2014 Ryan Lewis. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es6id: 20.2.2.17 +author: Ryan Lewis +description: Math.fround should return NaN if called with NaN. +---*/ + +assert.sameValue(Math.fround(NaN), NaN); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Math/fround/Math.fround_Zero.js b/js/src/tests/test262/built-ins/Math/fround/Math.fround_Zero.js new file mode 100644 index 0000000000..a5dc6fd1df --- /dev/null +++ b/js/src/tests/test262/built-ins/Math/fround/Math.fround_Zero.js @@ -0,0 +1,13 @@ +// Copyright (c) 2014 Ryan Lewis. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es6id: 20.2.2.17 +author: Ryan Lewis +description: Math.fround should return arg if called with 0 or -0. +---*/ + +assert.sameValue(Math.fround(0), 0, 'Math.fround(0)'); +assert.sameValue(Math.fround(-0), -0, 'Math.fround(-0)'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Math/fround/browser.js b/js/src/tests/test262/built-ins/Math/fround/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/Math/fround/browser.js diff --git a/js/src/tests/test262/built-ins/Math/fround/length.js b/js/src/tests/test262/built-ins/Math/fround/length.js new file mode 100644 index 0000000000..56190466ae --- /dev/null +++ b/js/src/tests/test262/built-ins/Math/fround/length.js @@ -0,0 +1,31 @@ +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es6id: 20.2.2.17 +description: > + Math.fround.length is 1. +info: | + Math.fround ( x ) + + 17 ECMAScript Standard Built-in Objects: + Every built-in Function object, including constructors, has a length + property whose value is an integer. Unless otherwise specified, this + value is equal to the largest number of named arguments shown in the + subclause headings for the function description, including optional + parameters. However, rest parameters shown using the form “...name” + are not included in the default argument count. + + Unless otherwise specified, the length property of a built-in Function + object has the attributes { [[Writable]]: false, [[Enumerable]]: false, + [[Configurable]]: true }. +includes: [propertyHelper.js] +---*/ + +assert.sameValue(Math.fround.length, 1); + +verifyNotEnumerable(Math.fround, "length"); +verifyNotWritable(Math.fround, "length"); +verifyConfigurable(Math.fround, "length"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Math/fround/name.js b/js/src/tests/test262/built-ins/Math/fround/name.js new file mode 100644 index 0000000000..c1f5ac6270 --- /dev/null +++ b/js/src/tests/test262/built-ins/Math/fround/name.js @@ -0,0 +1,28 @@ +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es6id: 20.2.2.17 +description: > + Math.fround.name is "fround". +info: | + Math.fround ( x ) + + 17 ECMAScript Standard Built-in Objects: + Every built-in Function object, including constructors, that is not + identified as an anonymous function has a name property whose value + is a String. + + Unless otherwise specified, the name property of a built-in Function + object, if it exists, has the attributes { [[Writable]]: false, + [[Enumerable]]: false, [[Configurable]]: true }. +includes: [propertyHelper.js] +---*/ + +assert.sameValue(Math.fround.name, "fround"); + +verifyNotEnumerable(Math.fround, "name"); +verifyNotWritable(Math.fround, "name"); +verifyConfigurable(Math.fround, "name"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Math/fround/not-a-constructor.js b/js/src/tests/test262/built-ins/Math/fround/not-a-constructor.js new file mode 100644 index 0000000000..d82e346651 --- /dev/null +++ b/js/src/tests/test262/built-ins/Math/fround/not-a-constructor.js @@ -0,0 +1,31 @@ +// Copyright (C) 2020 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-ecmascript-standard-built-in-objects +description: > + Math.fround does not implement [[Construct]], is not new-able +info: | + ECMAScript Function Objects + + Built-in function objects that are not identified as constructors do not + implement the [[Construct]] internal method unless otherwise specified in + the description of a particular function. + + sec-evaluatenew + + ... + 7. If IsConstructor(constructor) is false, throw a TypeError exception. + ... +includes: [isConstructor.js] +features: [Reflect.construct, arrow-function] +---*/ + +assert.sameValue(isConstructor(Math.fround), false, 'isConstructor(Math.fround) must return false'); + +assert.throws(TypeError, () => { + new Math.fround(); +}, '`new Math.fround()` throws TypeError'); + + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Math/fround/prop-desc.js b/js/src/tests/test262/built-ins/Math/fround/prop-desc.js new file mode 100644 index 0000000000..6d58e1e118 --- /dev/null +++ b/js/src/tests/test262/built-ins/Math/fround/prop-desc.js @@ -0,0 +1,19 @@ +// Copyright (C) 2017 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-math.fround +description: > + "fround" property of Math +info: | + Section 17: Every other data property described in clauses 18 through 26 + and in Annex B.2 has the attributes { [[Writable]]: true, + [[Enumerable]]: false, [[Configurable]]: true } unless otherwise specified. +includes: [propertyHelper.js] +---*/ + +verifyNotEnumerable(Math, "fround"); +verifyWritable(Math, "fround"); +verifyConfigurable(Math, "fround"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Math/fround/shell.js b/js/src/tests/test262/built-ins/Math/fround/shell.js new file mode 100644 index 0000000000..54371b7789 --- /dev/null +++ b/js/src/tests/test262/built-ins/Math/fround/shell.js @@ -0,0 +1,19 @@ +// GENERATED, DO NOT EDIT +// file: isConstructor.js +// Copyright (C) 2017 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +description: | + Test if a given function is a constructor function. +defines: [isConstructor] +---*/ + +function isConstructor(f) { + try { + Reflect.construct(function(){}, [], f); + } catch (e) { + return false; + } + return true; +} diff --git a/js/src/tests/test262/built-ins/Math/fround/ties.js b/js/src/tests/test262/built-ins/Math/fround/ties.js new file mode 100644 index 0000000000..5fdb467369 --- /dev/null +++ b/js/src/tests/test262/built-ins/Math/fround/ties.js @@ -0,0 +1,52 @@ +// Copyright (C) 2019 Tiancheng "Timothy" Gu. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-math.fround +description: Math.fround should use roundTiesToEven for conversion to binary32. +---*/ + +// We test five values against Math.fround, with their binary64 representation +// shown: +// a0 := 1.0 = 0x1p+0 +// a1 := 1.0000000596046448 = 0x1.000001p+0 +// a2 := 1.0000001192092896 = 0x1.000002p+0 +// a3 := 1.0000001788139343 = 0x1.000003p+0 +// a4 := 1.000000238418579 = 0x1.000004p+0 +// a5 := 1.0000002980232239 = 0x1.000005p+0 +// a6 := 1.0000003576278687 = 0x1.000006p+0 +// (Note: they are separated by 2 ** -24.) +// +// a0, a2, a4, and a6 are all representable exactly in binary32; however, while +// a0 and a4 have even mantissas in binary32, a2 and a6 have an odd mantissa +// when represented in that way. +// +// a1 is exactly halfway between a0 and a2, a3 between a2 and a4, and a5 +// between a4 and a6. By roundTiesToEven, Math.fround should favor a0 and a4 +// over a2 when they are equally close, and a4 over a6 when they are equally +// close. + +var a0 = 1.0; +var a1 = 1.0000000596046448; +var a2 = 1.0000001192092896; +var a3 = 1.0000001788139343; +var a4 = 1.000000238418579; +var a5 = 1.0000002980232239; +var a6 = 1.0000003576278687; + +assert.sameValue(Math.fround(a0), a0, 'Math.fround(a0)'); +assert.sameValue(Math.fround(a1), a0, 'Math.fround(a1)'); +assert.sameValue(Math.fround(a2), a2, 'Math.fround(a2)'); +assert.sameValue(Math.fround(a3), a4, 'Math.fround(a3)'); +assert.sameValue(Math.fround(a4), a4, 'Math.fround(a4)'); +assert.sameValue(Math.fround(a5), a4, 'Math.fround(a5)'); +assert.sameValue(Math.fround(a6), a6, 'Math.fround(a6)'); + +assert.sameValue(Math.fround(-a0), -a0, 'Math.fround(-a0)'); +assert.sameValue(Math.fround(-a1), -a0, 'Math.fround(-a1)'); +assert.sameValue(Math.fround(-a2), -a2, 'Math.fround(-a2)'); +assert.sameValue(Math.fround(-a3), -a4, 'Math.fround(-a3)'); +assert.sameValue(Math.fround(-a4), -a4, 'Math.fround(-a4)'); +assert.sameValue(Math.fround(-a5), -a4, 'Math.fround(-a5)'); +assert.sameValue(Math.fround(-a6), -a6, 'Math.fround(-a6)'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Math/fround/value-convertion.js b/js/src/tests/test262/built-ins/Math/fround/value-convertion.js new file mode 100644 index 0000000000..98e6b9d4a3 --- /dev/null +++ b/js/src/tests/test262/built-ins/Math/fround/value-convertion.js @@ -0,0 +1,27 @@ +// Copyright (C) 2016 The V8 Project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-math.fround +description: > + Convert to binary32 format and than to binary64 format +info: | + Math.fround ( x ) + + [...] + 3. Let x32 be the result of converting x to a value in IEEE 754-2008 binary32 + format using roundTiesToEven. + 4. Let x64 be the result of converting x32 to a value in IEEE 754-2008 + binary64 format. + 5. Return the ECMAScript Number value corresponding to x64. +---*/ + +assert.sameValue(Math.fround(4294967295), 4294967296, "2**32-1"); +assert.sameValue(Math.fround(4294967296), 4294967296, "2**32"); +assert.sameValue(Math.fround(4294967297), 4294967296, "2**32+1"); + +assert.sameValue(Math.fround(0.1), 0.10000000149011612, "0.1"); +assert.sameValue(Math.fround(0.2), 0.20000000298023224, "0.2"); +assert.sameValue(Math.fround(0.5), 0.5, "0.5"); + +reportCompare(0, 0); |