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
LibJS: Add & use non-BigInt overload of round_number_to_increment() #10385
Conversation
28fad04
to
278d912
Compare
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; |
There was a problem hiding this comment.
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.
There was a problem hiding this 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?
There was a problem hiding this 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:
(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.
I went through the spec, seems like the absolute largest value for |
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.
278d912
to
2781119
Compare
In preparation of this monstrosity, and because I'm not going to do double -> bigint -> double a dozen times: