line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# [[[ HEADER ]]] |
2
|
|
|
|
|
|
|
package RPerl::Operation::Expression::Operator::GMPFunctions; |
3
|
1
|
|
|
1
|
|
5
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
23
|
|
4
|
1
|
|
|
1
|
|
4
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
19
|
|
5
|
1
|
|
|
1
|
|
5
|
use RPerl::AfterSubclass; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
182
|
|
6
|
|
|
|
|
|
|
our $VERSION = 0.004_000; |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
# [[[ OO INHERITANCE ]]] |
9
|
1
|
|
|
1
|
|
7
|
use parent qw(RPerl::Operation::Expression::Operator); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
6
|
|
10
|
1
|
|
|
1
|
|
44
|
use RPerl::Operation::Expression::Operator; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
20
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
# [[[ CRITICS ]]] |
13
|
|
|
|
|
|
|
## no critic qw(ProhibitUselessNoCritic ProhibitMagicNumbers RequireCheckedSyscalls) # USER DEFAULT 1: allow numeric values & print operator |
14
|
|
|
|
|
|
|
## no critic qw(RequireInterpolationOfMetachars) # USER DEFAULT 2: allow single-quoted control characters & sigils |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
# [[[ INCLUDES ]]] |
17
|
1
|
|
|
1
|
|
4
|
use RPerl::DataType::GMPInteger; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
14
|
|
18
|
1
|
|
|
1
|
|
314
|
use Math::BigInt lib => 'GMP'; # we still actually use GMP in PERLOPS_PERLTYPES mode, albeit indirectly via Math::BigInt::GMP |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
4
|
|
19
|
1
|
|
|
1
|
|
759
|
use RPerl::Exporter 'import'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
8
|
|
20
|
|
|
|
|
|
|
our @EXPORT = qw( |
21
|
|
|
|
|
|
|
gmp_init gmp_init_set_unsigned_integer gmp_init_set_signed_integer |
22
|
|
|
|
|
|
|
gmp_set gmp_set_unsigned_integer gmp_set_signed_integer gmp_set_number gmp_set_string |
23
|
|
|
|
|
|
|
gmp_get_unsigned_integer gmp_get_signed_integer gmp_get_number gmp_get_string |
24
|
|
|
|
|
|
|
gmp_add gmp_sub gmp_mul gmp_mul_unsigned_integer gmp_mul_signed_integer gmp_sub_mul_unsigned_integer gmp_add_mul_unsigned_integer gmp_neg |
25
|
|
|
|
|
|
|
gmp_div_truncate_quotient |
26
|
|
|
|
|
|
|
gmp_cmp |
27
|
|
|
|
|
|
|
); |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
# [[[ OO PROPERTIES ]]] |
30
|
|
|
|
|
|
|
our hashref $properties = {}; |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
# [[[ SUBROUTINES & OO METHODS ]]] |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
# [[[ INITIALIZATION FUNCTIONS ]]] |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
# void mpz_init (mpz_t x) |
37
|
|
|
|
|
|
|
sub gmp_init { |
38
|
0
|
|
|
0
|
|
0
|
{ my void $RETURN_TYPE }; |
|
0
|
|
|
|
|
0
|
|
39
|
|
|
|
|
|
|
# ( my gmp_integer $x ) = @ARG; |
40
|
0
|
|
|
|
|
0
|
return; |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
# [[[ COMBINED INITIALIZATION AND ASSIGNMENT FUNCTIONS ]]] |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
# void mpz_init_set_ui (mpz_t rop, unsigned long int op) |
46
|
|
|
|
|
|
|
sub gmp_init_set_unsigned_integer { |
47
|
0
|
|
|
0
|
|
0
|
{ my void $RETURN_TYPE }; |
|
0
|
|
|
|
|
0
|
|
48
|
0
|
|
|
|
|
0
|
( my gmp_integer $rop, my unsigned_integer $op ) = @ARG; |
49
|
0
|
|
|
|
|
0
|
$rop->bzero(); |
50
|
0
|
|
|
|
|
0
|
$rop->badd($op); |
51
|
0
|
|
|
|
|
0
|
return; |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
# void mpz_init_set_si (mpz_t rop, signed long int op) |
55
|
|
|
|
|
|
|
sub gmp_init_set_signed_integer { |
56
|
0
|
|
|
0
|
|
0
|
{ my void $RETURN_TYPE }; |
|
0
|
|
|
|
|
0
|
|
57
|
0
|
|
|
|
|
0
|
( my gmp_integer $rop, my integer $op ) = @ARG; |
58
|
0
|
|
|
|
|
0
|
$rop->bzero(); |
59
|
0
|
|
|
|
|
0
|
$rop->badd($op); |
60
|
0
|
|
|
|
|
0
|
return; |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
# [[[ ASSIGNMENT FUNCTIONS ]]] |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
# void mpz_set (mpz_t rop, const mpz_t op) |
66
|
|
|
|
|
|
|
sub gmp_set { |
67
|
0
|
|
|
0
|
|
0
|
{ my void $RETURN_TYPE }; |
|
0
|
|
|
|
|
0
|
|
68
|
0
|
|
|
|
|
0
|
( my gmp_integer $rop, my gmp_integer $op ) = @ARG; |
69
|
0
|
|
|
|
|
0
|
$rop->bzero(); |
70
|
0
|
|
|
|
|
0
|
$rop->badd($op); |
71
|
0
|
|
|
|
|
0
|
return; |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
# void mpz_set_ui (mpz_t rop, unsigned long int op) |
75
|
|
|
|
|
|
|
sub gmp_set_unsigned_integer { |
76
|
0
|
|
|
0
|
|
0
|
{ my void $RETURN_TYPE }; |
|
0
|
|
|
|
|
0
|
|
77
|
0
|
|
|
|
|
0
|
( my gmp_integer $rop, my unsigned_integer $op ) = @ARG; |
78
|
0
|
|
|
|
|
0
|
$rop->bzero(); |
79
|
0
|
|
|
|
|
0
|
$rop->badd($op); |
80
|
0
|
|
|
|
|
0
|
return; |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
# void mpz_set_si (mpz_t rop, signed long int op) |
84
|
|
|
|
|
|
|
sub gmp_set_signed_integer { |
85
|
22
|
|
|
22
|
|
39
|
{ my void $RETURN_TYPE }; |
|
22
|
|
|
|
|
32
|
|
86
|
22
|
|
|
|
|
41
|
( my gmp_integer $rop, my integer $op ) = @ARG; |
87
|
22
|
|
|
|
|
80
|
$rop->bzero(); |
88
|
22
|
|
|
|
|
492
|
$rop->badd($op); |
89
|
22
|
|
|
|
|
2587
|
return; |
90
|
|
|
|
|
|
|
} |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
# void mpz_set_d (mpz_t rop, double op) |
93
|
|
|
|
|
|
|
sub gmp_set_number { |
94
|
0
|
|
|
0
|
|
0
|
{ my void $RETURN_TYPE }; |
|
0
|
|
|
|
|
0
|
|
95
|
0
|
|
|
|
|
0
|
( my gmp_integer $rop, my number $op ) = @ARG; |
96
|
0
|
|
|
|
|
0
|
$rop->bzero(); |
97
|
0
|
|
|
|
|
0
|
$rop->badd($op); |
98
|
0
|
|
|
|
|
0
|
return; |
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
# int mpz_set_str (mpz_t rop, const char *str, int base) |
102
|
|
|
|
|
|
|
sub gmp_set_string { |
103
|
0
|
|
|
0
|
|
0
|
{ my integer $RETURN_TYPE }; |
|
0
|
|
|
|
|
0
|
|
104
|
0
|
|
|
|
|
0
|
( my gmp_integer $rop, my string $str ) = @ARG; |
105
|
0
|
|
|
|
|
0
|
my Math::BigInt $tmp = Math::BigInt->new($str); |
106
|
0
|
|
|
|
|
0
|
$rop->bzero(); |
107
|
0
|
|
|
|
|
0
|
$rop->badd($tmp); |
108
|
0
|
|
|
|
|
0
|
return; |
109
|
|
|
|
|
|
|
} |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
# [[[ CONVERSION FUNCTIONS ]]] |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
# unsigned long int mpz_get_ui (const mpz_t op) |
114
|
|
|
|
|
|
|
sub gmp_get_unsigned_integer { |
115
|
0
|
|
|
0
|
|
0
|
{ my unsigned_integer $RETURN_TYPE }; |
|
0
|
|
|
|
|
0
|
|
116
|
0
|
|
|
|
|
0
|
( my gmp_integer $op ) = @ARG; |
117
|
0
|
|
|
|
|
0
|
return $op->numify(); |
118
|
|
|
|
|
|
|
} |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
# signed long int mpz_get_si (const mpz_t op) |
121
|
|
|
|
|
|
|
sub gmp_get_signed_integer { |
122
|
2
|
|
|
2
|
|
5
|
{ my integer $RETURN_TYPE }; |
|
2
|
|
|
|
|
4
|
|
123
|
2
|
|
|
|
|
5
|
( my gmp_integer $op ) = @ARG; |
124
|
2
|
|
|
|
|
16
|
return $op->numify(); |
125
|
|
|
|
|
|
|
} |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
# double mpz_get_d (const mpz_t op) |
128
|
|
|
|
|
|
|
sub gmp_get_number { |
129
|
0
|
|
|
0
|
|
|
{ my integer $RETURN_TYPE }; |
|
0
|
|
|
|
|
|
|
130
|
0
|
|
|
|
|
|
( my gmp_integer $op ) = @ARG; |
131
|
0
|
|
|
|
|
|
return $op->numify(); |
132
|
|
|
|
|
|
|
} |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
# char * mpz_get_str (char *str, int base, const mpz_t op) |
135
|
|
|
|
|
|
|
sub gmp_get_string { |
136
|
0
|
|
|
0
|
|
|
{ my string $RETURN_TYPE }; |
|
0
|
|
|
|
|
|
|
137
|
0
|
|
|
|
|
|
( my gmp_integer $op ) = @ARG; |
138
|
0
|
|
|
|
|
|
return $op->bstr(); |
139
|
|
|
|
|
|
|
} |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
# [[[ ARITHMETIC FUNCTIONS ]]] |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
# void mpz_add (mpz_t rop, const mpz_t op1, const mpz_t op2) |
144
|
|
|
|
|
|
|
sub gmp_add { |
145
|
0
|
|
|
0
|
|
|
{ my gmp_integer $RETURN_TYPE }; |
|
0
|
|
|
|
|
|
|
146
|
0
|
|
|
|
|
|
( my gmp_integer $rop, my gmp_integer $op1, my gmp_integer $op2 ) = @ARG; |
147
|
|
|
|
|
|
|
# in case $op1 and/or $op2 are the same variables as $rop, make copies so you don't zero them out before reading them |
148
|
0
|
|
|
|
|
|
my gmp_integer $op1_copy = $op1->copy(); |
149
|
0
|
|
|
|
|
|
my gmp_integer $op2_copy = $op2->copy(); |
150
|
0
|
|
|
|
|
|
$rop->bzero(); |
151
|
0
|
|
|
|
|
|
$rop->badd($op1_copy); |
152
|
0
|
|
|
|
|
|
$rop->badd($op2_copy); |
153
|
0
|
|
|
|
|
|
return; |
154
|
|
|
|
|
|
|
} |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
# void mpz_sub (mpz_t rop, const mpz_t op1, const mpz_t op2) |
157
|
|
|
|
|
|
|
sub gmp_sub { |
158
|
0
|
|
|
0
|
|
|
{ my gmp_integer $RETURN_TYPE }; |
|
0
|
|
|
|
|
|
|
159
|
0
|
|
|
|
|
|
( my gmp_integer $rop, my gmp_integer $op1, my gmp_integer $op2 ) = @ARG; |
160
|
0
|
|
|
|
|
|
my gmp_integer $op1_copy = $op1->copy(); |
161
|
0
|
|
|
|
|
|
my gmp_integer $op2_copy = $op2->copy(); |
162
|
0
|
|
|
|
|
|
$rop->bzero(); |
163
|
0
|
|
|
|
|
|
$rop->badd($op1_copy); |
164
|
0
|
|
|
|
|
|
$rop->bsub($op2_copy); |
165
|
0
|
|
|
|
|
|
return; |
166
|
|
|
|
|
|
|
} |
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
# void mpz_mul (mpz_t rop, const mpz_t op1, const mpz_t op2) |
169
|
|
|
|
|
|
|
sub gmp_mul { |
170
|
0
|
|
|
0
|
|
|
{ my void $RETURN_TYPE }; |
|
0
|
|
|
|
|
|
|
171
|
0
|
|
|
|
|
|
( my gmp_integer $rop, my gmp_integer $op1, my gmp_integer $op2 ) = @ARG; |
172
|
0
|
|
|
|
|
|
my gmp_integer $op1_copy = $op1->copy(); |
173
|
0
|
|
|
|
|
|
$rop->bzero(); |
174
|
0
|
|
|
|
|
|
$rop->badd($op1_copy); |
175
|
0
|
|
|
|
|
|
$rop->bmul($op2); |
176
|
0
|
|
|
|
|
|
return; |
177
|
|
|
|
|
|
|
} |
178
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
# void mpz_mul_ui (mpz_t rop, const mpz_t op1, unsigned long int op2) |
180
|
|
|
|
|
|
|
sub gmp_mul_unsigned_integer { |
181
|
0
|
|
|
0
|
|
|
{ my void $RETURN_TYPE }; |
|
0
|
|
|
|
|
|
|
182
|
0
|
|
|
|
|
|
( my gmp_integer $rop, my gmp_integer $op1, my unsigned_integer $op2 ) = @ARG; |
183
|
0
|
|
|
|
|
|
my gmp_integer $op1_copy = $op1->copy(); |
184
|
0
|
|
|
|
|
|
$rop->bzero(); |
185
|
0
|
|
|
|
|
|
$rop->badd($op1_copy); |
186
|
0
|
|
|
|
|
|
$rop->bmul($op2); |
187
|
0
|
|
|
|
|
|
return; |
188
|
|
|
|
|
|
|
} |
189
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
# void mpz_mul_si (mpz_t rop, const mpz_t op1, long int op2) |
191
|
|
|
|
|
|
|
sub gmp_mul_signed_integer { |
192
|
0
|
|
|
0
|
|
|
{ my void $RETURN_TYPE }; |
|
0
|
|
|
|
|
|
|
193
|
0
|
|
|
|
|
|
( my gmp_integer $rop, my gmp_integer $op1, my integer $op2 ) = @ARG; |
194
|
0
|
|
|
|
|
|
my gmp_integer $op1_copy = $op1->copy(); |
195
|
0
|
|
|
|
|
|
$rop->bzero(); |
196
|
0
|
|
|
|
|
|
$rop->badd($op1_copy); |
197
|
0
|
|
|
|
|
|
$rop->bmul($op2); |
198
|
0
|
|
|
|
|
|
return; |
199
|
|
|
|
|
|
|
} |
200
|
|
|
|
|
|
|
|
201
|
|
|
|
|
|
|
# void mpz_submul_ui (mpz_t rop, const mpz_t op1, unsigned long int op2) |
202
|
|
|
|
|
|
|
sub gmp_sub_mul_unsigned_integer { |
203
|
0
|
|
|
0
|
|
|
{ my gmp_integer $RETURN_TYPE }; |
|
0
|
|
|
|
|
|
|
204
|
0
|
|
|
|
|
|
( my gmp_integer $rop, my gmp_integer $op1, my unsigned_integer $op2 ) = @ARG; |
205
|
0
|
|
|
|
|
|
my gmp_integer $op1_copy = $op1->copy(); |
206
|
0
|
|
|
|
|
|
$op1_copy->bmul($op2); |
207
|
0
|
|
|
|
|
|
$rop->bsub($op1_copy); |
208
|
0
|
|
|
|
|
|
return; |
209
|
|
|
|
|
|
|
} |
210
|
|
|
|
|
|
|
|
211
|
|
|
|
|
|
|
# void mpz_addmul_ui (mpz_t rop, const mpz_t op1, unsigned long int op2) |
212
|
|
|
|
|
|
|
sub gmp_add_mul_unsigned_integer { |
213
|
0
|
|
|
0
|
|
|
{ my void $RETURN_TYPE }; |
|
0
|
|
|
|
|
|
|
214
|
0
|
|
|
|
|
|
( my gmp_integer $rop, my gmp_integer $op1, my unsigned_integer $op2 ) = @ARG; |
215
|
0
|
|
|
|
|
|
my gmp_integer $op1_copy = $op1->copy(); |
216
|
0
|
|
|
|
|
|
$op1_copy->bmul($op2); |
217
|
0
|
|
|
|
|
|
$rop->badd($op1_copy); |
218
|
0
|
|
|
|
|
|
return; |
219
|
|
|
|
|
|
|
} |
220
|
|
|
|
|
|
|
|
221
|
|
|
|
|
|
|
# void mpz_neg (mpz_t rop, const mpz_t op) |
222
|
|
|
|
|
|
|
sub gmp_neg { |
223
|
0
|
|
|
0
|
|
|
{ my void $RETURN_TYPE }; |
|
0
|
|
|
|
|
|
|
224
|
0
|
|
|
|
|
|
( my gmp_integer $rop, my gmp_integer $op1 ) = @ARG; |
225
|
0
|
|
|
|
|
|
my gmp_integer $op1_copy = $op1->copy(); |
226
|
0
|
|
|
|
|
|
$rop->bzero(); |
227
|
0
|
|
|
|
|
|
$rop->badd($op1_copy); |
228
|
0
|
|
|
|
|
|
$rop->bmul(Math::BigInt->bone('-')); |
229
|
0
|
|
|
|
|
|
return; |
230
|
|
|
|
|
|
|
} |
231
|
|
|
|
|
|
|
|
232
|
|
|
|
|
|
|
# [[[ DIVISION FUNCTIONS ]]] |
233
|
|
|
|
|
|
|
|
234
|
|
|
|
|
|
|
# void mpz_tdiv_q (mpz_t q, const mpz_t n, const mpz_t d) |
235
|
|
|
|
|
|
|
sub gmp_div_truncate_quotient { |
236
|
0
|
|
|
0
|
|
|
{ my void $RETURN_TYPE }; |
|
0
|
|
|
|
|
|
|
237
|
0
|
|
|
|
|
|
( my gmp_integer $q, my gmp_integer $n, my gmp_integer $d ) = @ARG; |
238
|
0
|
|
|
|
|
|
my gmp_integer $n_copy = $n->copy(); |
239
|
0
|
|
|
|
|
|
my gmp_integer $d_copy = $d->copy(); |
240
|
0
|
|
|
|
|
|
$q->bzero(); |
241
|
0
|
|
|
|
|
|
$q->badd($n_copy); |
242
|
0
|
|
|
|
|
|
$q->bdiv($d_copy); |
243
|
0
|
|
|
|
|
|
return; |
244
|
|
|
|
|
|
|
} |
245
|
|
|
|
|
|
|
|
246
|
|
|
|
|
|
|
# [[[ COMPARISON FUNCTIONS ]]] |
247
|
|
|
|
|
|
|
|
248
|
|
|
|
|
|
|
# int mpz_cmp (const mpz_t op1, const mpz_t op2) |
249
|
|
|
|
|
|
|
sub gmp_cmp { |
250
|
0
|
|
|
0
|
|
|
{ my integer $RETURN_TYPE }; |
|
0
|
|
|
|
|
|
|
251
|
0
|
|
|
|
|
|
( my gmp_integer $op1, my gmp_integer $op2 ) = @ARG; |
252
|
0
|
|
|
|
|
|
return $op1->bcmp($op2); |
253
|
|
|
|
|
|
|
} |
254
|
|
|
|
|
|
|
|
255
|
|
|
|
|
|
|
1; # end of class |