tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

argument-duration-precision-exact-numerical-values.js (1366B)


      1 // |reftest| skip-if(!this.hasOwnProperty('Temporal')) -- Temporal is not enabled unconditionally
      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    "PT9007199254740991.975424S",
     24    "case where floating point inaccuracy brings total below limit, positive"
     25  ],
     26  [
     27    {
     28      milliseconds: -4503599627370497_000,
     29      microseconds: -4503599627370495_000000,
     30    },
     31    "-PT9007199254740991.975424S",
     32    "case where floating point inaccuracy brings total below limit, negative"
     33  ],
     34 ];
     35 
     36 for (const [arg, string, descr] of cases) {
     37  const instance = Temporal.Duration.from(arg);  // should not throw
     38  assert.sameValue(instance.toString(), string, descr);
     39 }
     40 
     41 reportCompare(0, 0);