add big.Int Set, Abs, Neg and add test it

This commit is contained in:
tsingbx
2024-08-08 08:31:03 +08:00
parent b34334ba93
commit 0a8bad46b5
2 changed files with 134 additions and 14 deletions

View File

@@ -5,7 +5,7 @@ import (
"math/big"
)
func main() {
func fib() {
// Initialize two big ints with the first two numbers in the sequence.
a := big.NewInt(0)
b := big.NewInt(1)
@@ -23,3 +23,30 @@ func main() {
}
fmt.Println(a) // 100-digit Fibonacci number
}
func abs() {
a := big.NewInt(64)
b := big.NewInt(-52)
a.Set(b)
a.Abs(a)
a.Set(big.NewInt(-164))
a.Abs(a)
fmt.Println("value: ", a.String())
}
func neg() {
fmt.Println("value: ", big.NewInt(-64).Neg(big.NewInt(-64)))
fmt.Println("value: ", big.NewInt(64).Neg(big.NewInt(64)))
fmt.Println("value: ", big.NewInt(0).Neg(big.NewInt(0)))
}
func main() {
a := big.NewInt(64)
b := big.NewInt(-52)
c := big.NewInt(54)
fmt.Println("value:", a.Add(a, b))
fmt.Println("value:", a.Sub(b, c))
d := big.NewInt(10)
e := big.NewInt(4)
fmt.Println("value:", d.Mul(d, e))
}