Skip to content

Conversation

@catamorphism
Copy link
Contributor

Make it clear that it's acceptable for an implementation to use 128-bit integers and do the validity check in terms of nanoseconds.

Closes #3177

Make it clear that it's acceptable for an
implementation to use 128-bit integers and do the validity check
in terms of nanoseconds.
@codecov
Copy link

codecov bot commented Nov 19, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 96.49%. Comparing base (17e12be) to head (64d0424).
⚠️ Report is 9 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #3186   +/-   ##
=======================================
  Coverage   96.49%   96.49%           
=======================================
  Files          22       22           
  Lines       10305    10305           
  Branches     1846     1846           
=======================================
  Hits         9944     9944           
  Misses        311      311           
  Partials       50       50           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Collaborator

@ptomato ptomato left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

Copy link
Collaborator

@ptomato ptomato left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1. NOTE: The above step cannot be implemented directly using floating-point arithmetic. Multiplying by 10<sup>-3</sup>, 10<sup>-6</sup>, and 10<sup>-9</sup> respectively may be imprecise when _milliseconds_, _microseconds_, or _nanoseconds_ is an unsafe integer. This multiplication can be implemented in C++ with an implementation of `std::remquo()` with sufficient bits in the quotient. String manipulation will also give an exact result, since the multiplication is by a power of 10.
1. If abs(_normalizedSeconds_) ≥ 2<sup>53</sup>, return *false*.
1. Let _normalizedNanoseconds_ be _days_ × 86,400 × 10<sup>9</sup> + _hours_ × 3600 × 10<sup>9</sup> + _minutes_ × 60 × 10<sup>9</sup> + _seconds_ × 10<sup>9</sup> + ℝ(𝔽(_milliseconds_)) × 10<sup>6</sup> + ℝ(𝔽(_microseconds_)) × 10<sup>3</sup> + ℝ(𝔽(_nanoseconds_)).
1. NOTE: The above step cannot be implemented directly using 64-bit floating-point arithmetic. Multiplying by 10<sup>-3</sup>, 10<sup>-6</sup>, and 10<sup>-9</sup> respectively may be imprecise when _milliseconds_, _microseconds_, or _nanoseconds_ is an unsafe integer. The step can be implemented using 128-bit integers. It could also be implemented in C++ with an implementation of `std::remquo()` with sufficient bits in the quotient. String manipulation will also give an exact result, since the multiplication is by a power of 10.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"using 128 bit integers and performing all arithmetic on nanosecond values" maybe?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That sounds good; changed in 64d0424

@ptomato ptomato merged commit 1962c8b into tc39:main Nov 20, 2025
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Can IsValidDuration use multiplication instead of division?

3 participants