Skip to content

Conversation

@khwilliamson
Copy link
Contributor

These commits

  • add a calculation before the loop that saves calculations each iteration
  • replace floating multiplications each loop iteration with an integer increment, plus after the loop a call to ldexp

One question I have is can I just assume that Perl_ldexp exists and not have a fallback to Perl_pow? I think C99 requires all versions we need to be available, but it's not clear to me that perl.h guarantees one.

  • This set of changes does not require a perldelta entry.

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.
@t-a-k
Copy link
Contributor

t-a-k commented Dec 11, 2025

I'm suspicious whether replacing floating point multiplication to ldexp improves precision and/or speed:

  • in this case multiplicand (factor) is exact power of 2, so multiplication is always accurate without losing precision, as long as floating point is radix-2n.
  • many modern CPUs can do floating point multiplications with single instruction, while ldexp typically requires a library call or lengthy inlined code. So I'm afraid that this change may slow things down.

@tonycoz
Copy link
Contributor

tonycoz commented Dec 14, 2025

I think t-a-k is right.

@tonycoz
Copy link
Contributor

tonycoz commented Dec 14, 2025

Though I could see the ldexp being faster with -Dusequadmath or other soft floats (which are unlikely in modern general computing systems), but with doubles and probably long doubles the multiplication will likely be faster.

@khwilliamson
Copy link
Contributor Author

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.

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.

3 participants