Programming Language: Golang

Namespace/Package Name: math/big

Class/Type: Int

Method/Function: Cmp

Examples at hotexamples.com: 30

The `math/big` package in Go provides arbitrary-precision integer arithmetic operations. One of the important functions in this package is the `Cmp` method.

The `Cmp` method is used to compare two `big.Int` values and returns an integer corresponding to the result of the comparison. The possible return values are `-1` if the first value is less than the second one, `0` if they are equal, and `1` if the first value is greater than the second one.

Here are a few examples of how to use the `Cmp` method:

**Example 1:** Comparing two small `big.Int` values

In this example, two `big.Int` values are defined and compared using the `Cmp` method. As `a` is greater than `b`, the result of the comparison is `1`.

**Example 2:** Comparing two large `big.Int` values

The `Cmp` method is used to compare two `big.Int` values and returns an integer corresponding to the result of the comparison. The possible return values are `-1` if the first value is less than the second one, `0` if they are equal, and `1` if the first value is greater than the second one.

Here are a few examples of how to use the `Cmp` method:

import ( "fmt" "math/big" ) func main() { a := big.NewInt(15) b := big.NewInt(10) res := a.Cmp(b) fmt.Println(res) // Output: 1 }

In this example, two `big.Int` values are defined and compared using the `Cmp` method. As `a` is greater than `b`, the result of the comparison is `1`.

import ( "fmt" "math/big" ) func main() { a := new(big.Int) a.SetString("234567890123456789", 10) b := new(big.Int) b.SetString("123456789012345678", 10) res := a.Cmp(b) fmt.Println(res) // Output: 1 }In this example, two large `big.Int` values are defined using the `SetString` method and compared using the `Cmp` method. As `a` is greater than `b`, the result of the comparison is `1`. Package Library: The `math/big` package is part of the standard library in Go.

Frequently Used Methods

Frequently Used Methods

Frequently Used Methods

Related in langs

Frequently Used Methods

Related