Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

go

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!

like image 815
Ammar Bandukwala Avatar asked Nov 07 '22 00:11

Ammar Bandukwala


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
like image 168
ssemilla Avatar answered Nov 12 '22 15:11

ssemilla