From 812fe523729669ddd136c6c00f4b13b2550e7259 Mon Sep 17 00:00:00 2001 From: Philip Chimento Date: Mon, 26 Feb 2024 11:37:53 -0800 Subject: [PATCH] Editorial: Address too-large Duration values resulting from FP rounding There was an edge case, spotted by Anba, where floating-point rounding at the point of conversion from normalized form to Duration storage form, in BalanceTimeDuration, can result in a Duration storage form that fails assertions. For example, when a normalized time duration is the maximum possible value { [[TotalNanoseconds]]: 9007199254740991999999999 }, and BalanceTimeDuration is called with largestUnit nanoseconds. This is already covered by test262 tests. Closes: #2785 --- spec/duration.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/duration.html b/spec/duration.html index 7a6fd4ed5..858c92808 100644 --- a/spec/duration.html +++ b/spec/duration.html @@ -1197,7 +1197,7 @@

1. If abs(_years_) ≥ 232, return *false*. 1. If abs(_months_) ≥ 232, return *false*. 1. If abs(_weeks_) ≥ 232, return *false*. - 1. Let _normalizedSeconds_ be _days_ × 86,400 + _hours_ × 3600 + _minutes_ × 60 + _seconds_ + _milliseconds_ × 10-3 + _microseconds_ × 10-6 + _nanoseconds_ × 10-9. + 1. Let _normalizedSeconds_ be _days_ × 86,400 + _hours_ × 3600 + _minutes_ × 60 + _seconds_ + ℝ(𝔽(_milliseconds_)) × 10-3 + ℝ(𝔽(_microseconds_)) × 10-6 + ℝ(𝔽(_nanoseconds_)) × 10-9. 1. NOTE: The above step cannot be implemented directly using floating-point arithmetic. Multiplying by 10-3, 10-6, and 10-9 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_) ≥ 253, return *false*. 1. Return *true*.