-
-
Notifications
You must be signed in to change notification settings - Fork 610
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
feat: add C implementation for math/base/special/round
#745
Conversation
In
Math.round( -4.5 ) = -4
round( -4.5 ) = -5 Rest all tests passed and benchmarks cleared, this PR can have a review. |
@Pranavchiku This is an instance where we want to emulate JS behavior in C, I believe. Or maybe instead, we should do whatever IEEE 754-2008 specifies. Would be worth reading the spec and seeing what the default |
Okay, I will have a look at it. |
@stdlib/math/base/special/round
math/base/special/round
Accordin to https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/round: So I am confused if the rounding is to be done, then what rule will it follow? |
@Shashankss1205 What is the confusion? In short, JS behavior is to round ties in a manner similar to var v = round( 1.2 );
// returns 1.0
v = round( 1.8 );
// returns 2.0
v = round( 1.5 );
// returns 2.0
v = round( -1.2 );
// returns -1.0
v = round( -1.8 );
// returns -2.0
v = round( -1.5 );
// returns 1.0 Notice the behavior of |
Yeah understood, Thanks for confirming! |
The roundTiesToEven rounding-direction attribute shall be the default rounding-direction attribute for results in binary formats. The default rounding-direction attribute for results in decimal formats is language-defined, but should be roundTiesToEven.
roundTiesToEven, the floating-point number nearest to the infinitely precise result shall be delivered; if the two nearest floating-point numbers bracketing an unrepresentable infinitely precise result are equally near, the one with an even least significant digit shall be delivered Source: https://iremi.univ-reunion.fr/IMG/pdf/ieee-754-2008.pdf |
We can continue discussion at #1450, pushing implementation from https://tc39.es/ecma262/multipage/numbers-and-dates.html#sec-math.round. |
Subsequently merged in #1450. |
Resolves #735.
Checklist
@kgryte