Programming Language: Golang

Namespace/Package Name: math/big

Class/Type: Int

Method/Function: DivMod

Examples at hotexamples.com: 30

The `math/big` package in Go provides arbitrary-precision arithmetic operations for integers.

The `DivMod` function in `math/big` returns the quotient and the remainder of the mathematical division of two `Int` values. It takes two arguments: the dividend and the divisor.

**Example 1:**

This code prints:

In this example, we create two `Int` values `x` and `y` with the `NewInt` function. We then call the `DivMod` function with `x` and `y`. The variables `q` and `r` are passed as pointers to `DivMod`, and they are set to the quotient and remainder, respectively. Finally, we print the values of `q` and `r`.

**Example 2:**

This code prints:

The `DivMod` function in `math/big` returns the quotient and the remainder of the mathematical division of two `Int` values. It takes two arguments: the dividend and the divisor.

package main import ( "fmt" "math/big" ) func main() { x := big.NewInt(50) y := big.NewInt(8) var q, r big.Int q.DivMod(x, y, &r) fmt.Printf("quotient: %v, remainder: %v\n", &q, &r) }

This code prints:

quotient: 6, remainder: 2

In this example, we create two `Int` values `x` and `y` with the `NewInt` function. We then call the `DivMod` function with `x` and `y`. The variables `q` and `r` are passed as pointers to `DivMod`, and they are set to the quotient and remainder, respectively. Finally, we print the values of `q` and `r`.

package main import ( "fmt" "math/big" ) func main() { x := big.NewInt(123456789) y := big.NewInt(987654321) var q, r big.Int q.DivMod(x, y, &r) fmt.Printf("quotient: %v, remainder: %v\n", &q, &r) }

This code prints:

quotient: 0, remainder: 123456789In this example, we divide `x` by `y`, which results in a quotient of 0 and a remainder of `x` itself. This demonstrates that `DivMod` returns the correct values even when the dividend is smaller than the divisor. The `math/big` package is a standard library in Go.

Frequently Used Methods

Frequently Used Methods

Frequently Used Methods

Related in langs

Frequently Used Methods

Related