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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
|
/*
Copyright 2021 Jeroen van Rijn <nom@duclavier.com>.
Made available under Odin's BSD-3 license.
This file collects public proc maps and their aliases.
*/
package math_big
/*
=== === === === === === === === === === === === === === === === === === === === === === === ===
Basic arithmetic.
See `public.odin`.
=== === === === === === === === === === === === === === === === === === === === === === === ===
*/
/*
High-level addition. Handles sign.
*/
add :: proc {
/*
int_add :: proc(dest, a, b: ^Int, allocator := context.allocator) -> (err: Error)
*/
int_add,
/*
Adds the unsigned `DIGIT` immediate to an `Int`, such that the
`DIGIT` doesn't have to be turned into an `Int` first.
int_add_digit :: proc(dest, a: ^Int, digit: DIGIT, allocator := context.allocator) -> (err: Error)
*/
int_add_digit,
rat_add_rat,
rat_add_int,
int_add_rat,
}
/*
err = sub(dest, a, b);
*/
sub :: proc {
/*
int_sub :: proc(dest, a, b: ^Int) -> (err: Error)
*/
int_sub,
/*
int_sub_digit :: proc(dest, a: ^Int, digit: DIGIT) -> (err: Error)
*/
int_sub_digit,
rat_sub_rat,
rat_sub_int,
int_sub_rat,
}
/*
=== === === === === === === === === === === === === === === === === === === === === === === ===
Comparisons.
See `compare.odin`.
=== === === === === === === === === === === === === === === === === === === === === === === ===
*/
is_initialized :: proc {
/*
int_is_initialized :: proc(a: ^Int) -> bool
*/
int_is_initialized,
}
is_zero :: proc {
/*
int_is_zero :: proc(a: ^Int) -> bool
*/
int_is_zero,
/*
rat_is_zero :: proc(a: ^Rat) -> bool
*/
rat_is_zero,
}
is_positive :: proc {
/*
int_is_positive :: proc(a: ^Int) -> bool
*/
int_is_positive,
rat_is_positive,
}
is_pos :: is_positive
is_negative :: proc {
/*
int_is_negative :: proc(a: ^Int) -> bool
*/
int_is_negative,
rat_is_negative,
}
is_neg :: is_negative
is_even :: proc {
/*
int_is_even :: proc(a: ^Int) -> bool
*/
int_is_even,
rat_is_even,
}
is_odd :: proc {
/*
int_is_odd :: proc(a: ^Int) -> bool
*/
int_is_odd,
rat_is_odd,
}
is_power_of_two :: proc {
/*
platform_int_is_power_of_two :: proc(a: int) -> bool
*/
platform_int_is_power_of_two,
/*
int_is_power_of_two :: proc(a: ^Int) -> (res: bool)
*/
int_is_power_of_two,
}
compare :: proc {
/*
Compare two `Int`s, signed.
int_compare :: proc(a, b: ^Int) -> Comparison_Flag
*/
int_compare,
/*
Compare an `Int` to an unsigned number upto the size of the backing type.
int_compare_digit :: proc(a: ^Int, u: DIGIT) -> Comparison_Flag
*/
int_compare_digit,
}
cmp :: compare
compare_magnitude :: proc {
/*
Compare the magnitude of two `Int`s, unsigned.
*/
int_compare_magnitude,
}
cmp_mag :: compare_magnitude
/*
=== === === === === === === === === === === === === === === === === === === === === === === ===
Initialization and other helpers.
See `helpers.odin`.
=== === === === === === === === === === === === === === === === === === === === === === === ===
*/
destroy :: proc {
/*
Clears one or more `Int`s and dellocates their backing memory.
int_destroy :: proc(integers: ..^Int)
*/
int_destroy,
internal_rat_destroy,
}
|