Standard library / math/big
big.Float.SetRat()
Convert a rational using receiver precision and mode; repeating binary fractions require rounding. This method writes to the receiver (use a separate destination to preserve inputs when needed). Expected stdout: '0.34375 Above\n'.
Formal Syntax & Structure
go syntaxgo
func (z *Float) SetRat(x *Rat) *FloatParameters & Attributes
| Name | Type | Description |
|---|---|---|
| x | *Rat | Numeric operand supplied to this method. |
Return Value
*Float
Returns the result described above; see the example for the observed behavior.
Working Example
Example Snippetgo
package main
import ( "fmt" "math/big")
func main() { z := new(big.Float).SetPrec(4).SetRat(big.NewRat(1, 3)) fmt.Println(z.Text('f', 5), z.Acc())}