Programming Language: Golang

Namespace/Package Name: math/big

Class/Type: Int

Method/Function: Sub

Examples at hotexamples.com: 30

The go math.big package library provides support for arbitrary precision arithmetic operations on integers through the use of big.Int. The big.Int.Sub function subtracts the second big integer argument from the first one and returns the result.

**Example 1:**

In the above example, we first create two big.Int variables `num1` and `num2` with values 100000 and 50000 respectively. We then create another big.Int variable `diff` and use the `Sub` function to subtract num2 from num1 and store the result in `diff`. Finally, we print the difference.

**Example 2:**

package main import ( "fmt" "math/big" ) func main() { num1 := big.NewInt(100000) num2 := big.NewInt(50000) diff := big.NewInt(0) diff.Sub(num1, num2) fmt.Println(diff) }

In the above example, we first create two big.Int variables `num1` and `num2` with values 100000 and 50000 respectively. We then create another big.Int variable `diff` and use the `Sub` function to subtract num2 from num1 and store the result in `diff`. Finally, we print the difference.

package main import ( "fmt" "math/big" ) func main() { num1 := big.NewInt(0).Exp(big.NewInt(2), big.NewInt(100), nil) num2 := big.NewInt(0).SetInt64(100) diff := big.NewInt(0) diff.Sub(num1, num2) fmt.Println(diff) }In this example, we use the `Exp` function of the big.Int type to calculate 2^100, and then subtract it from 100 using the `Sub` function. The resulting difference is printed.

Frequently Used Methods

Frequently Used Methods

Frequently Used Methods

Related in langs

Frequently Used Methods

Related