Debian Codegraph @

js/src/tests/test262/built-ins/Temporal/Duration/compare/argument-duration-precision-exact-numerical-values.js

raw
1 // |reftest| shell-option(--enable-temporal) skip-if(!this.hasOwnProperty('Temporal')||!xulRuntime.shell) -- Temporal is not enabled unconditionally, requires shell-options
2 // Copyright (C) 2023 Igalia, S.L. All rights reserved.
3 // This code is governed by the BSD license found in the LICENSE file.
4
5 /*---
6 esid: sec-temporal.duration.from
7 description: >
8 Duration-like argument performs the range check with minimal floating point
9 precision loss
10 features: [Temporal]
11 ---*/
12
13 // Based on a test case by André Bargull
14
15 const cases = [
16 [
17 {
18 milliseconds: 4503599627370497_000, // ℝ(𝔽(4503599627370497000)) = 4503599627370497024
19 microseconds: 4503599627370495_000000, // ℝ(𝔽(4503599627370495000000)) = 4503599627370494951424
20 },
21 // 4503599627370497024 / 1000 + 4503599627370494951424 / 1000000 is
22 // 9007199254740991.975424, which is below the limit of 2**53
23 "case where floating point inaccuracy brings total below limit, positive"
24 ],
25 [
26 {
27 milliseconds: -4503599627370497_000,
28 microseconds: -4503599627370495_000000,
29 },
30 "case where floating point inaccuracy brings total below limit, negative"
31 ],
32 ];
33
34 for (const [arg, descr] of cases) {
35 assert.sameValue(Temporal.Duration.compare(arg, arg), 0, descr);
36 }
37
38 reportCompare(0, 0);