-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdec128_example_test.go
More file actions
125 lines (111 loc) · 1.93 KB
/
dec128_example_test.go
File metadata and controls
125 lines (111 loc) · 1.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
package dec128
import "fmt"
func ExampleFromString() {
a := FromString("0.123456789")
fmt.Println(a.String())
// Output:
// 0.123456789
}
func ExampleDec128_Abs() {
a := FromString("-123.45")
fmt.Println(a.Abs())
// Output:
// 123.45
}
func ExampleDec128_Add() {
a := FromString("123.45")
b := FromString("678.90")
fmt.Println(a.Add(b))
// Output:
// 802.35
}
func ExampleDec128_Sub() {
a := FromString("123.45")
b := FromString("678.90")
fmt.Println(a.Sub(b))
// Output:
// -555.45
}
func ExampleDec128_Mul() {
a := FromString("123.45")
b := FromString("678.90")
fmt.Println(a.Mul(b))
// Output:
// 83810.205
}
func ExampleDec128_Div() {
SetDefaultScale(19)
a := FromString("1")
b := FromString("3")
fmt.Println(a.Div(b))
// Output:
// 0.3333333333333333333
}
func ExampleDec128_Sqrt() {
a := FromString("4")
fmt.Println(a.Sqrt())
// Output:
// 2
}
func ExampleMax() {
a := FromString("1.1")
b := FromString("1.2")
c := FromString("1.3")
d := FromString("-1")
fmt.Println(Max(a, b))
fmt.Println(Max(a, b, c))
fmt.Println(Max(a, b, c, d))
// Output:
// 1.2
// 1.3
// 1.3
}
func ExampleMin() {
a := FromString("1.1")
b := FromString("1.2")
c := FromString("1.3")
d := FromString("-1")
fmt.Println(Min(a, b))
fmt.Println(Min(a, b, c))
fmt.Println(Min(a, b, c, d))
// Output:
// 1.1
// 1.1
// -1
}
func ExampleDec128_PowInt() {
a := FromString("2")
fmt.Println(a.PowInt(-3))
// Output:
// 0.125
}
func ExampleDec128_Mod() {
a := FromString("7")
b := FromString("3")
fmt.Println(a.Mod(b))
// Output:
// 1
}
func ExampleSum() {
a := FromString("1")
b := FromString("2")
c := FromString("3.1")
fmt.Println(Sum(a, b))
fmt.Println(Sum(a, b, c))
// Output:
// 3
// 6.1
}
func ExampleAvg() {
a := FromString("1")
b := FromString("2")
c := FromString("3")
d := FromString("1.1")
fmt.Println(Avg(a, b))
fmt.Println(Avg(a, b, c))
fmt.Println(Avg(a, b, c, d))
// Output:
// 1.5
// 2
// 1.775
}