@@ -4,37 +4,37 @@ module suilend::decimal {
4
4
const WAD : u256 = 1000000000000000000 ;
5
5
const U64_MAX : u256 = 18446744073709551615 ;
6
6
7
- public struct Decimal has copy , store , drop {
8
- value: u256
7
+ public struct Decimal has copy , drop , store {
8
+ value: u256 ,
9
9
}
10
10
11
11
public fun from (v: u64 ): Decimal {
12
12
Decimal {
13
- value: (v as u256 ) * WAD
13
+ value: (v as u256 ) * WAD ,
14
14
}
15
15
}
16
16
17
17
public fun from_percent (v: u8 ): Decimal {
18
18
Decimal {
19
- value: (v as u256 ) * WAD / 100
19
+ value: (v as u256 ) * WAD / 100 ,
20
20
}
21
21
}
22
22
23
23
public fun from_percent_u64 (v: u64 ): Decimal {
24
24
Decimal {
25
- value: (v as u256 ) * WAD / 100
25
+ value: (v as u256 ) * WAD / 100 ,
26
26
}
27
27
}
28
28
29
29
public fun from_bps (v: u64 ): Decimal {
30
30
Decimal {
31
- value: (v as u256 ) * WAD / 10_000
31
+ value: (v as u256 ) * WAD / 10_000 ,
32
32
}
33
33
}
34
34
35
35
public fun from_scaled_val (v: u256 ): Decimal {
36
36
Decimal {
37
- value: v
37
+ value: v,
38
38
}
39
39
}
40
40
@@ -44,13 +44,13 @@ module suilend::decimal {
44
44
45
45
public fun add (a: Decimal , b: Decimal ): Decimal {
46
46
Decimal {
47
- value: a.value + b.value
47
+ value: a.value + b.value,
48
48
}
49
49
}
50
50
51
51
public fun sub (a: Decimal , b: Decimal ): Decimal {
52
52
Decimal {
53
- value: a.value - b.value
53
+ value: a.value - b.value,
54
54
}
55
55
}
56
56
@@ -64,13 +64,13 @@ module suilend::decimal {
64
64
65
65
public fun mul (a: Decimal , b: Decimal ): Decimal {
66
66
Decimal {
67
- value: (a.value * b.value) / WAD
67
+ value: (a.value * b.value) / WAD ,
68
68
}
69
69
}
70
70
71
71
public fun div (a: Decimal , b: Decimal ): Decimal {
72
72
Decimal {
73
- value: (a.value * WAD ) / b.value
73
+ value: (a.value * WAD ) / b.value,
74
74
}
75
75
}
76
76
@@ -144,7 +144,23 @@ module suilend::decimal {
144
144
145
145
#[test_only]
146
146
module suilend ::decimal_tests {
147
- use suilend::decimal::{add, sub, mul, div, floor, ceil, pow, lt, gt, le, ge, from, from_percent, saturating_sub, saturating_floor};
147
+ use suilend::decimal::{
148
+ add,
149
+ sub,
150
+ mul,
151
+ div,
152
+ floor,
153
+ ceil,
154
+ pow,
155
+ lt,
156
+ gt,
157
+ le,
158
+ ge,
159
+ from,
160
+ from_percent,
161
+ saturating_sub,
162
+ saturating_floor
163
+ };
148
164
149
165
#[test]
150
166
fun test_basic () {
@@ -164,7 +180,10 @@ module suilend::decimal_tests {
164
180
assert !(saturating_sub (a, b) == from (0 ), 0 );
165
181
assert !(saturating_sub (b, a) == from (1 ), 0 );
166
182
assert !(saturating_floor (from (18446744073709551615 )) == 18446744073709551615 , 0 );
167
- assert !(saturating_floor (add (from (18446744073709551615 ), from (1 ))) == 18446744073709551615 , 0 );
183
+ assert !(
184
+ saturating_floor (add (from (18446744073709551615 ), from (1 ))) == 18446744073709551615 ,
185
+ 0 ,
186
+ );
168
187
}
169
188
170
189
#[test]
0 commit comments