Standard library / math/big
big.Int.DivMod()
Compute Euclidean quotient and nonnegative modulus; divisor zero panics. Unlike QuoRem, remainder is always nonnegative. This method writes to the receiver (use a separate destination to preserve inputs when needed). Expected stdout: '-3 2\n'.
Formal Syntax & Structure
go syntaxgo
func (z *Int) DivMod(x, y, m *Int) (*Int, *Int)Parameters & Attributes
| Name | Type | Description |
|---|---|---|
| x | *Int | Numeric operand supplied to this method. |
| y | *Int | Numeric operand supplied to this method. |
| m | *Int | Destination for the modulus. |
Return Value
(*Int, *Int)
Returns the result described above; see the example for the observed behavior.
Working Example
Example Snippetgo
package main
import ( "fmt" "math/big")
func main() { q, m := new(big.Int).DivMod(big.NewInt(-7), big.NewInt(3), new(big.Int)) fmt.Println(q, m)}