-
Notifications
You must be signed in to change notification settings - Fork 18.7k
Closed
Labels
Milestone
Description
float32(Rat.Float64(x)) is not the same as Rat.Float32(x) in general (adjusted for
correct arguments, etc.):
package main
import (
"fmt"
"math/big"
)
func main() {
const x = 340282356779733661637539395458142568447
fmt.Println(float64(x), float32(x))
z, ok := new(big.Rat).SetString("340282356779733661637539395458142568447")
if !ok {
panic("SetString failed")
}
t, _ := z.Float64()
fmt.Println(t, float32(t))
}
produces:
3.4028235677973366e+38 3.4028235e+38
3.4028235677973366e+38 +Inf
i.e., we need a Rat.Float32 implementation with correct rounding for 32bit floats.