1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 07:07:45 +00:00

LibJS: Replace RoundTowardsZero with truncate

This is an editorial change in the Temporal spec. See:
409ab66
This commit is contained in:
Timothy Flynn 2022-10-14 09:29:16 -04:00 committed by Linus Groh
parent 019211bcb4
commit 4fbec2e8b3
6 changed files with 12 additions and 12 deletions

View file

@ -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.

View file

@ -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).

View file

@ -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).

View file

@ -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).

View file

@ -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 }),

View file

@ -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).