The floats package provides types for handling multi-precision floating-point numbers.
Supported types are:
- Float16: Half-precision floating-point format
- Float32: Single-precision floating-point format
- Float64: Double-precision floating-point format
- Float128: Quadruple-precision floating-point format
- Float256: Octuple-precision floating-point format
package main
import (
"fmt"
"github.com/shogo82148/floats"
)
func main() {
a := floats.NewFloat16(1.0)
b := floats.NewFloat16(2.0)
fmt.Printf("%g + %g = %g\n", a, b, a.Add(b))
fmt.Printf("%g - %g = %g\n", a, b, a.Sub(b))
fmt.Printf("%g * %g = %g\n", a, b, a.Mul(b))
fmt.Printf("%g / %g = %g\n", a, b, a.Quo(b))
}The package passes tests generated by Berkeley TestFloat.
Some code has been developed with reference to Go's standard library and chewxy/math32. Please refer to the NOTICE for the copyright information of these libraries.