Standard library / math/big
big.Rat.Sub()
Subtract rational numbers exactly, returning the mutated receiver. This method writes to the receiver (use a separate destination to preserve inputs when needed). Expected stdout: '7/12\n'.
Formal Syntax & Structure
go syntaxgo
func (z *Rat) Sub(x, y *Rat) *RatParameters & Attributes
| Name | Type | Description |
|---|---|---|
| x | *Rat | Numeric operand supplied to this method. |
| y | *Rat | Numeric operand supplied to this method. |
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).Sub(big.NewRat(3, 4), big.NewRat(1, 6)))}