Standard library / math/big
big.Float.Uint64()
The documented contract truncates toward zero and reports accuracy; negative values saturate to zero and excessive positive values to MaxUint64. Go 1.23.2 locally returns Exact for 3.75, contrary to the documented Below. For finite nonnegative values, check IsInt and range independently or use Int(nil) with IsUint64 before converting. Expected stdout: '3 Below false\n3 Exact\n'.
Formal Syntax & Structure
go syntaxgo
func (x *Float) Uint64() (uint64, Accuracy)Return Value
(uint64, Accuracy)
Returns the result described above; see the example for the observed behavior.
Working Example
Example Snippetgo
package main
import ( "fmt" "math/big")
func main() { x := big.NewFloat(3.75) i, a := x.Int(nil) if i != nil && i.IsUint64() { fmt.Println(i.Uint64(), a, x.IsInt()) } v, acc := big.NewFloat(3).Uint64() fmt.Println(v, acc)}