I have a library that gives floats in mantissa and exponent values for no loss of precision.
Mantissa: 375400000000000
Exponent: -9
How do I turn this into a float32 or float64 in golang?
I gave it a shot here but the number is definitely not coming out correctly: https://go.dev/play/p/8wMxhq11qwS
package main
import (
"fmt"
"math/big"
)
func main() {
mantissa := 375600000000000
exp := int8(-9)
var price big.Float
mant := big.NewFloat(float64(mantissa))
price.SetMantExp(mant, int(exp))
fmt.Println("price: ", price.String())
fmt.Println("mant: ", mantissa)
fmt.Println("exp: ", exp)
}
Apparently this doesn't work because big.Float is represented by sign × mantissa × 2**exponent
when I need sign x mantissa x 10 ^ exp