Standard library / math/big

big.Rat.SetFrac()

Set the rational from arbitrary-precision numerator and nonzero denominator; normalize sign and reduce the fraction. This method writes to the receiver (use a separate destination to preserve inputs when needed). Expected stdout: '-3/4\n'.

Formal Syntax & Structure

go syntaxgo
func (z *Rat) SetFrac(a, b *Int) *Rat

Parameters & Attributes

NameTypeDescription
a*IntNumerator.
b*IntNonzero denominator.

Return Value

*Rat

Returns the result described above; see the example for the observed behavior.

Working Example

Example Snippetgo
package main
import (  "fmt"  "math/big")
func main() {  fmt.Println(new(big.Rat).SetFrac(big.NewInt(6), big.NewInt(-8)))}
Go Reference