How to take the exponent of math/big.Float in Go?

Viewed 962

I couldn't find anything in the API. Converting the number to a math/big.Int and back is not an option because the fractional component is significant to my calculation.


I'll end up repeatedly multiplying if there's no API, but that's a dissatisfying solution (math/big.Int.Exp is just O(log(n))) which might not be practical when I run into this problem again.

Thanks!

1 Answers

You may use MantExp() to take the exponent of a big.Float for a particular base/mantissa. Note that the formula for calculating the exponent for a given mantissa is:

x == mant × 2**exp
Related