test262/test/built-ins/Temporal/Duration/from/argument-duration-precision...

39 lines
1.2 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// Copyright (C) 2023 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-temporal.duration.from
description: >
Duration-like argument performs the range check with minimal floating point
precision loss
features: [Temporal]
---*/
// Based on a test case by André Bargull
const cases = [
[
{
milliseconds: 4503599627370497_000, // (𝔽(4503599627370497000)) = 4503599627370497024
microseconds: 4503599627370495_000000, // (𝔽(4503599627370495000000)) = 4503599627370494951424
},
// 4503599627370497024 / 1000 + 4503599627370494951424 / 1000000 is
// 9007199254740991.975424, which is below the limit of 2**53
"PT9007199254740991.975424S",
"case where floating point inaccuracy brings total below limit, positive"
],
[
{
milliseconds: -4503599627370497_000,
microseconds: -4503599627370495_000000,
},
"-PT9007199254740991.975424S",
"case where floating point inaccuracy brings total below limit, negative"
],
];
for (const [arg, string, descr] of cases) {
const instance = Temporal.Duration.from(arg); // should not throw
assert.sameValue(instance.toString(), string, descr);
}