I'm looking for an algorithm that takes a 64-bit floating point number and outputs an exponent and coefficient so the input can be represented in the form float64 input = coefficient * 10 ^ exponent
.
Supposedly this is 'not trivial', and many implementations of accurate decimal formats for Golang (which doesn't have a built-in decimal type) have some kind of hack for it like converting to a string and parsing that. While that solution does work in the packages I've seen, it just seems 'proper' to do it the mathematical/computer science-y way.
It may be not 100% precise, but you can use Log10:
package main
import (
"fmt"
"math"
)
func parts(v float64) (float64, int) {
e := math.Floor(math.Log10(v))
c := v / math.Pow(10, e)
return c, int(e)
}
func main() {
c, e := parts(1348.234e134)
fmt.Printf("%v * 10^%v", c, e) // 1.3482339999999997 * 10^137
}