8 ms·
This looks like an ideal case for something like ldexp(), but I couldn't find an equivalent function in Java at first glance. A lookup table seems like a bit o
by drv 11y ago
This looks like an ideal case for something like ldexp(), but I couldn't find an equivalent function in Java at first glance.
A lookup table seems like a bit of a shame for something that should be inherently fast in binary floating point, but it is probably the next best thing if poking around in the floating point bit representation isn't possible.
- stephencanon 11y agoldexp( ) is a surprisingly expensive operation because it has to handle edge cases correctly; even if you don't hit those edge cases the best implementation of the fast path on most architectures is approximately extract exponent, add adjustment, check result, branch to fixup if out of range, insert exponent. If the range of adjustments you need to support is small, and you're not totally load-store bound, a lookup table is faster. (That's not to say that Java shouldn't have ldexp( ), just that it's not a fix-all.)
- nwhitehead 11y agoJava does have Math.scalb() which would work. It would be interesting to see how that compares to the Math.pow() and table lookup methods.