-
Notifications
You must be signed in to change notification settings - Fork 168
Improve number to string conversions #400
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
Conversation
Any chance this also fixes the rounding issues on Windows? |
Windows was supposed to behave as
After discussing this with Fabrice, it appears
The conversion tests now all pass on all platforms. The extreme |
9b458a8
to
cce7876
Compare
integer conversions: - improve `u32toa_radix` and `u64toa_radix`, add `i32toa_radix` - use `i32toa_radix` for small ints in `js_number_toString` floating point conversions (`js_dtoa`): - complete rewrite with fewer calls to `snprintf` - remove `JS_DTOA_FORMAT`, define 4 possible modes for `js_dtoa` - remove the radix argument in `js_dtoa` - merge `js_dtoa1` into `js_dtoa` - add `js_dtoa_infinite` for non finite values - simplify sign handling - handle locale specific decimal point transparently helper function `js_fcvt`: - simplify `js_fcvt`, remove `js_fcvt1`, reduce overhead - round up manually instead of using `fesetround(FE_UPWARD)`. helper function `js_ecvt`: - document `js_ecvt` and `js_ecvt1` behavior - avoid redundant `js_ecvt1` calls in `js_ecvt` - fixed buffer contents, no buffer copies - simplify decimal point handling - round up manually instead of using `fesetround(FE_UPWARD)`. miscellaneous: - remove `CONFIG_PRINTF_RNDN`. This fixes some of the conversion errors on Windows. Updated the tests accordingly - this fixes a v8.sh bug on macOS: `0.5.toFixed(0)` used to produce `0` instead of `1` - add regression tests, update test_conv unit tests - add benchmarks for `toFixed`, `toPrecision` and `toExponential` number methods - benchmarks show all conversions are now 40 to 45% faster (M2)
integer conversions:
u32toa_radix
andu64toa_radix
, addi32toa_radix
i32toa_radix
for small ints injs_number_toString
floating point conversions (
js_dtoa
):snprintf
JS_DTOA_FORMAT
, define 4 possible modes forjs_dtoa
js_dtoa
js_dtoa1
intojs_dtoa
js_dtoa_infinite
for non finite valueshelper function
js_fcvt
:js_fcvt
, removejs_fcvt1
, reduce overheadfesetround(FE_UPWARD)
.helper function
js_ecvt
:js_ecvt
andjs_ecvt1
behaviorjs_ecvt1
calls injs_ecvt
fesetround(FE_UPWARD)
.miscellaneous:
0.5.toFixed(0)
used to produce0
instead of1
toFixed
,toPrecision
andtoExponential
number methods