Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LibJS: Add & use non-BigInt overload of round_number_to_increment() #10385

Merged

Conversation

linusg
Copy link
Member

@linusg linusg commented Oct 6, 2021

In preparation of this monstrosity, and because I'm not going to do double -> bigint -> double a dozen times:

@linusg linusg requested a review from IdanHo October 6, 2021 22:06
@linusg linusg force-pushed the libjs-temporal-double-roundnumbertoincrement branch 2 times, most recently from 28fad04 to 278d912 Compare October 6, 2021 22:48
VERIFY(rounding_mode == "ceil"sv || rounding_mode == "floor"sv || rounding_mode == "trunc"sv || rounding_mode == "halfExpand"sv);

// 3. Let quotient be x / increment.
auto quotient = x / (double)increment;
Copy link
Member

Choose a reason for hiding this comment

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

This cast to double can be out of range, not sure if increment can have the full i64 range here though.

Copy link
Member

@IdanHo IdanHo left a comment

Choose a reason for hiding this comment

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

While the implementation looks fine (and does make the example user nicer), it seems like it assumes a lot about the maximal values for the arguments with all of those casts, will all of the current users in the spec meet those requirements?

Copy link
Member Author

@linusg linusg left a comment

Choose a reason for hiding this comment

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

Fun fact: this is the firs time ever I look at V8's in progress Temporal implementation, and they do literally exactly the same:

image

(don't know how to link to it, gerrit is terrible)

So, that should answer both of your questions - there are plenty of cases where the number range is way less than what this can handle, and a i64 -> double cast seems fine as well.

@alimpfard
Copy link
Member

I went through the spec, seems like the absolute largest value for increment is 3.6 * 10^14, which is safe to represent in both i64 and double.
That addresses my own question, though it would be much better if the spec told us about this, rather than me going through the tree of usages for RoundNumberToIncrement.

@IdanHo
Copy link
Member

IdanHo commented Oct 7, 2021

I went through the spec, seems like the absolute largest value for increment is 3.6 * 10^14, which is safe to represent in both i64 and double. That addresses my own question, though it would be much better if the spec told us about this, rather than me going through the tree of usages for RoundNumberToIncrement.

Sounds good to me then, might want to add a small comment, but up to you

Unlike the spec we chose BigInt for the input and output types here as
it was being used with ℝ(ns), ns being of type BigInt, in one place and
a conversion to double would not be safe.
Since in many places we'll have double input values, let's add a double
overload of this function to avoid awkward conversions and expensive
allocations.
@linusg linusg force-pushed the libjs-temporal-double-roundnumbertoincrement branch from 278d912 to 2781119 Compare October 7, 2021 11:54
@linusg linusg merged commit ef004c6 into SerenityOS:master Oct 7, 2021
@linusg linusg deleted the libjs-temporal-double-roundnumbertoincrement branch October 7, 2021 12:00
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.

None yet

3 participants