Float (Shift) in Go

Posted by GoDoc
Public (Editable by Users)

A nonzero finite Float represents a multi-precision floating point number

Go
Edit
package main

import (
	"fmt"
	"math/big"
)

func main() {
	// Implement Float "shift" by modifying the (binary) exponents directly.
	for s := -5; s <= 5; s++ {
		x := big.NewFloat(0.5)
		x.SetMantExp(x, x.MantExp(nil)+s) // shift x by s
		fmt.Println(x)
	}
}