diff options
author | Timothy Flynn <trflynn89@pm.me> | 2022-10-14 09:29:16 -0400 |
---|---|---|
committer | Linus Groh <mail@linusgroh.de> | 2022-10-15 18:05:02 +0200 |
commit | 4fbec2e8b3141ca5b895d7c9bb17f8b0cf22bca2 (patch) | |
tree | 29971af439038d8be24443955e54ffe27ba78ccf /Userland | |
parent | 019211bcb4b789c2e0d3ce2b44e7023932664d75 (diff) | |
download | serenity-4fbec2e8b3141ca5b895d7c9bb17f8b0cf22bca2.zip |
LibJS: Replace RoundTowardsZero with truncate
This is an editorial change in the Temporal spec. See:
https://github.com/tc39/proposal-temporal/commit/409ab66
Diffstat (limited to 'Userland')
6 files changed, 12 insertions, 12 deletions
diff --git a/Userland/Libraries/LibJS/Runtime/Temporal/AbstractOperations.cpp b/Userland/Libraries/LibJS/Runtime/Temporal/AbstractOperations.cpp index 1ef8719f13..71fbafc5ab 100644 --- a/Userland/Libraries/LibJS/Runtime/Temporal/AbstractOperations.cpp +++ b/Userland/Libraries/LibJS/Runtime/Temporal/AbstractOperations.cpp @@ -381,7 +381,7 @@ ThrowCompletionOr<SecondsStringPrecision> to_seconds_string_precision(VM& vm, Ob if (fractional_digits_value.is_nan() || fractional_digits_value.is_infinity()) return vm.template throw_completion<RangeError>(ErrorType::OptionIsNotValidValue, fractional_digits_value, "fractionalSecondDigits"sv); - // 12. Let fractionalDigitCount be RoundTowardsZero(โ(fractionalDigitsVal)). + // 12. Let fractionalDigitCount be truncate(โ(fractionalDigitsVal)). auto fractional_digit_count_unchecked = trunc(fractional_digits_value.as_double()); // 13. If fractionalDigitCount < 0 or fractionalDigitCount > 9, throw a RangeError exception. diff --git a/Userland/Libraries/LibJS/Runtime/Temporal/Duration.cpp b/Userland/Libraries/LibJS/Runtime/Temporal/Duration.cpp index 1a3e8df37d..7d83c551e5 100644 --- a/Userland/Libraries/LibJS/Runtime/Temporal/Duration.cpp +++ b/Userland/Libraries/LibJS/Runtime/Temporal/Duration.cpp @@ -1582,19 +1582,19 @@ String temporal_duration_to_string(double years, double months, double weeks, do // 1. Let sign be ! DurationSign(years, months, weeks, days, hours, minutes, seconds, milliseconds, microseconds, nanoseconds). auto sign = duration_sign(years, months, weeks, days, hours, minutes, seconds, milliseconds, microseconds, nanoseconds); - // 2. Set microseconds to microseconds + RoundTowardsZero(nanoseconds / 1000). + // 2. Set microseconds to microseconds + truncate(nanoseconds / 1000). microseconds += trunc(nanoseconds / 1000); // 3. Set nanoseconds to remainder(nanoseconds, 1000). nanoseconds = fmod(nanoseconds, 1000); - // 4. Set milliseconds to milliseconds + RoundTowardsZero(microseconds / 1000). + // 4. Set milliseconds to milliseconds + truncate(microseconds / 1000). milliseconds += trunc(microseconds / 1000); // 5. Set microseconds to remainder(microseconds, 1000). microseconds = fmod(microseconds, 1000); - // 6. Set seconds to seconds + RoundTowardsZero(milliseconds / 1000). + // 6. Set seconds to seconds + truncate(milliseconds / 1000). seconds += trunc(milliseconds / 1000); // 7. Set milliseconds to remainder(milliseconds, 1000). diff --git a/Userland/Libraries/LibJS/Runtime/Temporal/InstantPrototype.cpp b/Userland/Libraries/LibJS/Runtime/Temporal/InstantPrototype.cpp index 6b382757bc..096b6a0f21 100644 --- a/Userland/Libraries/LibJS/Runtime/Temporal/InstantPrototype.cpp +++ b/Userland/Libraries/LibJS/Runtime/Temporal/InstantPrototype.cpp @@ -63,7 +63,7 @@ JS_DEFINE_NATIVE_FUNCTION(InstantPrototype::epoch_seconds_getter) // 3. Let ns be instant.[[Nanoseconds]]. auto& ns = instant->nanoseconds(); - // 4. Let s be RoundTowardsZero(โ(ns) / 10^9). + // 4. Let s be truncate(โ(ns) / 10^9). auto [s, _] = ns.big_integer().divided_by(Crypto::UnsignedBigInteger { 1'000'000'000 }); // 5. Return ๐ฝ(s). @@ -80,7 +80,7 @@ JS_DEFINE_NATIVE_FUNCTION(InstantPrototype::epoch_milliseconds_getter) // 3. Let ns be instant.[[Nanoseconds]]. auto& ns = instant->nanoseconds(); - // 4. Let ms be RoundTowardsZero(โ(ns) / 10^6). + // 4. Let ms be truncate(โ(ns) / 10^6). auto [ms, _] = ns.big_integer().divided_by(Crypto::UnsignedBigInteger { 1'000'000 }); // 5. Return ๐ฝ(ms). @@ -97,7 +97,7 @@ JS_DEFINE_NATIVE_FUNCTION(InstantPrototype::epoch_microseconds_getter) // 3. Let ns be instant.[[Nanoseconds]]. auto& ns = instant->nanoseconds(); - // 4. Let ยตs be RoundTowardsZero(โ(ns) / 10^3). + // 4. Let ยตs be truncate(โ(ns) / 10^3). auto [us, _] = ns.big_integer().divided_by(Crypto::UnsignedBigInteger { 1'000 }); // 5. Return โค(ยตs). diff --git a/Userland/Libraries/LibJS/Runtime/Temporal/PlainDate.cpp b/Userland/Libraries/LibJS/Runtime/Temporal/PlainDate.cpp index a3e0f96008..c9986cfa20 100644 --- a/Userland/Libraries/LibJS/Runtime/Temporal/PlainDate.cpp +++ b/Userland/Libraries/LibJS/Runtime/Temporal/PlainDate.cpp @@ -295,7 +295,7 @@ DateDurationRecord difference_iso_date(VM& vm, i32 year1, u8 month1, u8 day1, i3 // h. If largestUnit is "week", then if (largest_unit == "week"sv) { - // i. Set weeks to RoundTowardsZero(days / 7). + // i. Set weeks to truncate(days / 7). weeks = trunc(days / 7); // ii. Set days to remainder(days, 7). diff --git a/Userland/Libraries/LibJS/Runtime/Temporal/ZonedDateTime.cpp b/Userland/Libraries/LibJS/Runtime/Temporal/ZonedDateTime.cpp index 9a9b7019f8..7acba1931c 100644 --- a/Userland/Libraries/LibJS/Runtime/Temporal/ZonedDateTime.cpp +++ b/Userland/Libraries/LibJS/Runtime/Temporal/ZonedDateTime.cpp @@ -450,7 +450,7 @@ ThrowCompletionOr<NanosecondsToDaysResult> nanoseconds_to_days(VM& vm, Crypto::S // 4. If Type(relativeTo) is not Object or relativeTo does not have an [[InitializedTemporalZonedDateTime]] internal slot, then if (!relative_to_value.is_object() || !is<ZonedDateTime>(relative_to_value.as_object())) { - // a. Return the Record { [[Days]]: RoundTowardsZero(nanoseconds / dayLengthNs), [[Nanoseconds]]: (abs(nanoseconds) modulo dayLengthNs) ร sign, [[DayLength]]: dayLengthNs }. + // a. Return the Record { [[Days]]: truncate(nanoseconds / dayLengthNs), [[Nanoseconds]]: (abs(nanoseconds) modulo dayLengthNs) ร sign, [[DayLength]]: dayLengthNs }. return NanosecondsToDaysResult { .days = nanoseconds.divided_by(day_length_ns).quotient.to_double(), .nanoseconds = Crypto::SignedBigInteger { nanoseconds.unsigned_value() }.divided_by(day_length_ns).remainder.multiplied_by(Crypto::SignedBigInteger { sign }), diff --git a/Userland/Libraries/LibJS/Runtime/Temporal/ZonedDateTimePrototype.cpp b/Userland/Libraries/LibJS/Runtime/Temporal/ZonedDateTimePrototype.cpp index 8cb5157afe..1d5c914c5b 100644 --- a/Userland/Libraries/LibJS/Runtime/Temporal/ZonedDateTimePrototype.cpp +++ b/Userland/Libraries/LibJS/Runtime/Temporal/ZonedDateTimePrototype.cpp @@ -352,7 +352,7 @@ JS_DEFINE_NATIVE_FUNCTION(ZonedDateTimePrototype::epoch_seconds_getter) // 3. Let ns be zonedDateTime.[[Nanoseconds]]. auto& ns = zoned_date_time->nanoseconds(); - // 4. Let s be RoundTowardsZero(โ(ns) / 10^9). + // 4. Let s be truncate(โ(ns) / 10^9). auto s = ns.big_integer().divided_by(Crypto::UnsignedBigInteger { 1'000'000'000 }).quotient; // 5. Return ๐ฝ(s). @@ -369,7 +369,7 @@ JS_DEFINE_NATIVE_FUNCTION(ZonedDateTimePrototype::epoch_milliseconds_getter) // 3. Let ns be zonedDateTime.[[Nanoseconds]]. auto& ns = zoned_date_time->nanoseconds(); - // 4. Let ms be RoundTowardsZero(โ(ns) / 10^6). + // 4. Let ms be truncate(โ(ns) / 10^6). auto ms = ns.big_integer().divided_by(Crypto::UnsignedBigInteger { 1'000'000 }).quotient; // 5. Return ๐ฝ(ms). @@ -386,7 +386,7 @@ JS_DEFINE_NATIVE_FUNCTION(ZonedDateTimePrototype::epoch_microseconds_getter) // 3. Let ns be zonedDateTime.[[Nanoseconds]]. auto& ns = zoned_date_time->nanoseconds(); - // 4. Let ยตs be RoundTowardsZero(โ(ns) / 10^3). + // 4. Let ยตs be truncate(โ(ns) / 10^3). auto us = ns.big_integer().divided_by(Crypto::UnsignedBigInteger { 1'000 }).quotient; // 5. Return โค(ยตs). |