-
Notifications
You must be signed in to change notification settings - Fork 603
grok_bin_oct_hex: Minor improvements to precision, speed #23975
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
base: blead
Are you sure you want to change the base?
Conversation
Underscores in numbers are much less common than digits, and its unlikely that this iteration of the loop through all the digits will still have a running total of 0.
grok_bin_oct_hex: Move comments And reflow. This is in preparation for the next commit.
We can compute outside the loop the exact value at which the next iteration wil overflow, saving some operations
This replaces a floating multiply each loop iteration with an integer increment, plus after the loop completes, a call to ldexp() or pow(). Most of the floating multiplies are done on integral values, so not much precision is lost, but this gets it down to just one precision-losing operation.
ce2b1e3 to
054d093
Compare
|
I'm suspicious whether replacing floating point multiplication to
|
|
I think t-a-k is right. |
|
Though I could see the ldexp being faster with |
|
I'm unsure of this, but I thought that as the mantissa gets overflowed the ldexp could save one or two floating point operations that each lose precision. |
Multiplying by a positive power of two (after conversion to double that's an exponent and a implicit 1 mantissa) doesn't lose any more precision than the step of converting a 64-bit integer to a 53-bit mantissa in the first place. |
These commits
ldexpOne question I have is can I just assume that
Perl_ldexpexists and not have a fallback toPerl_pow? I think C99 requires all versions we need to be available, but it's not clear to me thatperl.hguarantees one.