Int64.xs

filter: Statementstmt 76.7% 550 / 717 Branchbran 54.7% 326 / 596 Conditioncond n/a MC/DCmcdc n/a Subroutinesub n/a Podpod n/a totaltotal 66.7% 876 / 1313 SCAR 0
CC
0
Cov
0%
CRAP 0
« blib/lib/Math/Int64/native_if_available.pm ↑ Summary isaac64.h »
1 /* -*- Mode: C -*- */
2  
3 #define PERL_NO_GET_CONTEXT 1
4  
5 #include "EXTERN.h"
6 #include "perl.h"
7 #include "XSUB.h"
8  
9 #define NEED_sv_2pvbyte
10 #define NEED_sv_2pv_flags
11 #include "ppport.h"
12  
13 static int may_die_on_overflow;
14 static int may_use_native;
15  
16 #ifdef HAS_STDINT_H
17 #include <stdint.h>
18 #endif
19  
20 #define NV_0x1p15 ((NV)32768)
21 #define NV_0x1p16 ((NV)65536)
22 #define NV_0x1p31 (NV_0x1p16 * NV_0x1p15)
23 #define NV_0x1p32 (NV_0x1p16 * NV_0x1p16)
24 #define NV_0x1p63 (NV_0x1p32 * NV_0x1p31)
25 #define NV_0x1p64 (NV_0x1p32 * NV_0x1p32)
26  
27 #ifdef _MSC_VER
28 #include <stdlib.h>
29  
30 #ifndef INT64_MAX
31 #define INT64_MAX _I64_MAX
32 #endif
33 #ifndef INT64_MIN
34 #define INT64_MIN _I64_MIN
35 #endif
36 #ifndef UINT64_MAX
37 #define UINT64_MAX _UI64_MAX
38 #endif
39 #ifndef UINT32_MAX
40 #define UINT32_MAX _UI32_MAX
41 #endif
42  
43 #endif
44  
45 #ifdef USE_INT64_T
46 /* do nothing */
47  
48 #elif defined(USE___INT64)
49 typedef __int64 int64_t;
50 typedef unsigned __int64 uint64_t;
51  
52 #elif defined(USE_INT64_DI)
53 typedef int int64_t __attribute__ ((__mode__ (DI)));
54 typedef unsigned int uint64_t __attribute__ ((__mode__ (DTI)));
55  
56 #else
57 #error "No int64 type define was passed to the compiler!"
58 #endif
59  
60 #if ((defined _MSC_VER) || (defined INT64_MY_NV2U64))
61  
62 /* Old MS compilers do not implement the double->uint64 conversion and
63 * silently do a double->int64 conversion instead. See
64 * http://connect.microsoft.com/VisualStudio/feedback/details/270762/error-in-converting-double-to-unsigned-long-long */
65  
66 /* I don't trust atof, so I generate 2**-32 from simpler constants and
67 * hope the optimizer will do its work properly */
68  
69 #define NV_0x1p_4 ((NV)0.0625)
70 #define NV_0x1p_16 (NV_0x1p_4 * NV_0x1p_4 * NV_0x1p_4 * NV_0x1p_4)
71 #define NV_0x1p_32 (NV_0x1p_16 * NV_0x1p_16)
72  
73 static uint64_t
74 nv2u64(NV nv) {
75 if ((nv > 0.0) && (nv < NV_0x1p64)) {
76 uint64_t h = nv * NV_0x1p_32;
77 uint64_t l = nv - (NV)(int64_t)h * NV_0x1p32;
78 return ((h << 32) + l);
79 }
80 return 0;
81 }
82 #define NV2U64(nv) nv2u64(nv)
83  
84 # if defined(_MSC_VER) && _MSC_VER >= 1300
85 # define U642NV(u64) ((NV)(u64))
86 # else
87 static NV
88 u642nv(uint64_t u64) {
89 unsigned long h = u64 >> 32;
90 unsigned long l = u64 & 0xffffffff;
91 return (NV_0x1p32 * h) + (NV)l;
92 }
93 # define U642NV(nv) u642nv(nv)
94 # endif
95 #else
96 #define NV2U64(nv) ((uint64_t)(nv))
97 #define U642NV(u64) ((NV)(u64))
98 #endif
99  
100 #if (PERL_VERSION >= 10)
101  
102 #ifndef cop_hints_fetch_pvs
103 #define cop_hints_fetch_pvs(cop, key, flags) \
104 Perl_refcounted_he_fetch(aTHX_ (cop)->cop_hints_hash, NULL, STR_WITH_LEN(key), (flags), 0)
105 #endif
106  
107 static int
108 58 check_die_on_overflow_hint(pTHX) {
109 58 SV *hint = cop_hints_fetch_pvs(PL_curcop, "Math::Int64::die_on_overflow", 0);
110 58 ▶ return (hint && SvTRUE(hint));
Branch: 2 branches
BranchTrueFalseTotal
return (hint && SvTRUE(hint)); 58 0 58
return (hint && SvTRUE(hint)); 30 28 58
111 }
112  
113 static int
114 16 check_use_native_hint(pTHX) {
115 16 SV *hint = cop_hints_fetch_pvs(PL_curcop, "Math::Int64::native_if_available", 0);
116 16 ▶ return (hint && SvTRUE(hint));
Branch: 2 branches
BranchTrueFalseTotal
return (hint && SvTRUE(hint)); 16 0 16
return (hint && SvTRUE(hint)); 16 0 16
117 }
118  
119 #define use_native (may_use_native && check_use_native_hint(aTHX))
120  
121 #else
122  
123 static int
124 check_die_on_overflow_hint(pTHX) {
125 return 1;
126 }
127  
128 static int
129 check_use_native_hint(pTHX) {
130 return 1;
131 }
132  
133 #define use_native may_use_native
134  
135 #endif
136  
137 static void
138 58 overflow(pTHX_ const char *msg) {
139 58 ▶ if (check_die_on_overflow_hint(aTHX))
Branch: 1 branch
BranchTrueFalseTotal
if (check_die_on_overflow_hint(aTHX)) 30 28 58
140 30 Perl_croak(aTHX_ "Math::Int64 overflow: %s", msg);
141 28 }
142  
143 static const char *out_of_bounds_error_s = "Number is out of bounds for int64_t conversion";
144 static const char *out_of_bounds_error_u = "Number is out of bounds for uint64_t conversion";
145 static const char *mul_error = "Multiplication overflows";
146 static const char *add_error = "Addition overflows";
147 static const char *sub_error = "Subtraction overflows";
148 static const char *inc_error = "Increment operation wraps";
149 static const char *dec_error = "Decrement operation wraps";
150 static const char *div_by_0_error = "Illegal division by zero";
151 static const char *pow_error = "Exponentiation overflows";
152 static const char *invalid_length_error_s = "Invalid length for int64";
153 static const char *invalid_length_error_u = "Invalid length for uint64";
154 static const char *invalid_BER_error = "Invalid BER encoding";
155  
156 1 static void croak_string(pTHX_ const char *str) {
157 1 Perl_croak(aTHX_ "%s", str);
158 }
159  
160 #include "strtoint64.h"
161 #include "isaac64.h"
162  
163 #define MY_CXT_KEY "Math::Int64::isaac64_state" XS_VERSION
164 typedef struct {
165 isaac64_state_t is;
166 } my_cxt_t;
167 START_MY_CXT
168  
169 #if defined(INT64_BACKEND_NV)
170 # define BACKEND "NV"
171 # define SvI64Y SvNVX
172 # define SvI64_onY SvNOK_on
173 # define SVt_I64 SVt_NV
174 #elif defined(INT64_BACKEND_IV)
175 # define BACKEND "IV"
176 # define SvI64Y SvIVX
177 # define SvI64_onY SvIOK_on
178 # define SVt_I64 SVt_IV
179 #else
180 # error "unsupported backend"
181 #endif
182  
183 static int
184 0 SvI64OK(pTHX_ SV *sv) {
185 0 ▶ if (SvROK(sv)) {
Branch: 1 branch
BranchTrueFalseTotal
if (SvROK(sv)) { 0 0 0
186 0 SV *si64 = SvRV(sv);
187 0 ▶ return (si64 && (SvTYPE(si64) >= SVt_I64) && sv_isa(sv, "Math::Int64"));
Branch: 3 branches
BranchTrueFalseTotal
return (si64 && (SvTYPE(si64) >= SVt_I64) && sv_isa(sv, "Math::Int64")); 0 0 0
return (si64 && (SvTYPE(si64) >= SVt_I64) && sv_isa(sv, "Math::Int64")); 0 0 0
return (si64 && (SvTYPE(si64) >= SVt_I64) && sv_isa(sv, "Math::Int64")); 0 0 0
188 }
189 0 return 0;
190 }
191  
192 static int
193 0 SvU64OK(pTHX_ SV *sv) {
194 0 ▶ if (SvROK(sv)) {
Branch: 1 branch
BranchTrueFalseTotal
if (SvROK(sv)) { 0 0 0
195 0 SV *su64 = SvRV(sv);
196 0 ▶ return (su64 && (SvTYPE(su64) >= SVt_I64) && sv_isa(sv, "Math::UInt64"));
Branch: 3 branches
BranchTrueFalseTotal
return (su64 && (SvTYPE(su64) >= SVt_I64) && sv_isa(sv, "Math::UInt64")); 0 0 0
return (su64 && (SvTYPE(su64) >= SVt_I64) && sv_isa(sv, "Math::UInt64")); 0 0 0
return (su64 && (SvTYPE(su64) >= SVt_I64) && sv_isa(sv, "Math::UInt64")); 0 0 0
197 }
198 0 return 0;
199 }
200  
201 static SV *
202 1681 newSVi64(pTHX_ int64_t i64) {
203 SV *sv;
204 1681 SV *si64 = newSV(0);
205 1681 ▶ SvUPGRADE(si64, SVt_I64);
Branch: 1 branch
BranchTrueFalseTotal
SvUPGRADE(si64, SVt_I64); 1681 0 1681
206 1681 SvI64_onY(si64);
207 1681 sv = newRV_noinc(si64);
208 1681 sv_bless(sv, gv_stashpvs("Math::Int64", TRUE));
209 1681 *(int64_t*)(&(SvI64Y(si64))) = i64;
210 1681 SvREADONLY_on(si64);
211 1681 return sv;
212 }
213  
214 static SV *
215 2050 newSVu64(pTHX_ uint64_t u64) {
216 SV *sv;
217 2050 SV *su64 = newSV(0);
218 2050 ▶ SvUPGRADE(su64, SVt_I64);
Branch: 1 branch
BranchTrueFalseTotal
SvUPGRADE(su64, SVt_I64); 2050 0 2050
219 2050 SvI64_onY(su64);
220 2050 sv = newRV_noinc(su64);
221 2050 sv_bless(sv, gv_stashpvs("Math::UInt64", TRUE));
222 2050 *(int64_t*)(&(SvI64Y(su64))) = u64;
223 2050 SvREADONLY_on(su64);
224 2050 return sv;
225 }
226  
227 #define SvI64X(sv) (*(int64_t*)(&(SvI64Y(SvRV(sv)))))
228 #define SvU64X(sv) (*(uint64_t*)(&(SvI64Y(SvRV(sv)))))
229  
230 static SV *
231 3179 SvSI64(pTHX_ SV *sv) {
232 3179 ▶ if (SvROK(sv)) {
Branch: 1 branch
BranchTrueFalseTotal
if (SvROK(sv)) { 3179 0 3179
233 3179 SV *si64 = SvRV(sv);
234 3179 ▶ if (si64 && (SvTYPE(si64) >= SVt_I64))
Branch: 2 branches
BranchTrueFalseTotal
if (si64 && (SvTYPE(si64) >= SVt_I64)) 3179 0 3179
if (si64 && (SvTYPE(si64) >= SVt_I64)) 3179 0 3179
235 3179 return si64;
236 }
237 0 croak_string(aTHX_ "internal error: reference to NV expected");
238 0 return NULL; /* this dead code is a workaround for OpenWatcom */
239 }
240  
241 static SV *
242 3213 SvSU64(pTHX_ SV *sv) {
243 3213 ▶ if (SvROK(sv)) {
Branch: 1 branch
BranchTrueFalseTotal
if (SvROK(sv)) { 3213 0 3213
244 3213 SV *su64 = SvRV(sv);
245 3213 ▶ if (su64 && (SvTYPE(su64) >= SVt_I64))
Branch: 2 branches
BranchTrueFalseTotal
if (su64 && (SvTYPE(su64) >= SVt_I64)) 3213 0 3213
if (su64 && (SvTYPE(su64) >= SVt_I64)) 3213 0 3213
246 3213 return su64;
247 }
248 0 croak_string(aTHX_ "internal error: reference to NV expected");
249 0 return NULL; /* this dead code is a workaround for OpenWatcom */
250 }
251  
252 #define SvI64x(sv) (*(int64_t*)(&(SvI64Y(SvSI64(aTHX_ sv)))))
253 #define SvU64x(sv) (*(uint64_t*)(&(SvI64Y(SvSU64(aTHX_ sv)))))
254  
255 static int64_t
256 1791 SvI64(pTHX_ SV *sv) {
257 1791 ▶ if (SvROK(sv)) {
Branch: 1 branch
BranchTrueFalseTotal
if (SvROK(sv)) { 1118 673 1791
258 1118 SV *si64 = SvRV(sv);
259 1118 ▶ if (si64 && SvOBJECT(si64)) {
Branch: 2 branches
BranchTrueFalseTotal
if (si64 && SvOBJECT(si64)) { 1118 0 1118
if (si64 && SvOBJECT(si64)) { 1118 0 1118
260 GV *method;
261 1118 HV *stash = SvSTASH(si64);
262 1118 ▶ char const * classname = HvNAME_get(stash);
Branch: 6 branches
BranchTrueFalseTotal
char const * classname = HvNAME_get(stash); 1118 0 1118
char const * classname = HvNAME_get(stash); 1118 0 1118
char const * classname = HvNAME_get(stash); 0 1118 1118
char const * classname = HvNAME_get(stash); 0 0 0
char const * classname = HvNAME_get(stash); 1118 0 1118
char const * classname = HvNAME_get(stash); 0 1118 1118
263 1118 ▶ if (memcmp(classname, "Math::", 6) == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (memcmp(classname, "Math::", 6) == 0) { 1116 2 1118
264 int u;
265 1116 ▶ if (classname[6] == 'U') {
Branch: 1 branch
BranchTrueFalseTotal
if (classname[6] == 'U') { 4 1112 1116
266 4 u = 1;
267 4 classname += 7;
268 }
269 else {
270 1112 u = 0;
271 1112 classname += 6;
272 }
273 1116 ▶ if (memcmp(classname, "Int64", 6) == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (memcmp(classname, "Int64", 6) == 0) { 1116 0 1116
274 1116 ▶ if (SvTYPE(si64) < SVt_I64)
Branch: 1 branch
BranchTrueFalseTotal
if (SvTYPE(si64) < SVt_I64) 0 1116 1116
275 0 ▶ Perl_croak(aTHX_ "Wrong internal representation for %s object", HvNAME_get(stash));
Branch: 6 branches
BranchTrueFalseTotal
Perl_croak(aTHX_ "Wrong internal representation for %s object", HvNAME_get(stash)); 0 0 0
Perl_croak(aTHX_ "Wrong internal representation for %s object", HvNAME_get(stash)); 0 0 0
Perl_croak(aTHX_ "Wrong internal representation for %s object", HvNAME_get(stash)); 0 0 0
Perl_croak(aTHX_ "Wrong internal representation for %s object", HvNAME_get(stash)); 0 0 0
Perl_croak(aTHX_ "Wrong internal representation for %s object", HvNAME_get(stash)); 0 0 0
Perl_croak(aTHX_ "Wrong internal representation for %s object", HvNAME_get(stash)); 0 0 0
276 1116 ▶ if (u) {
Branch: 1 branch
BranchTrueFalseTotal
if (u) { 4 1112 1116
277 4 uint64_t u = *(uint64_t*)(&(SvI64Y(si64)));
278 4 ▶ if (may_die_on_overflow && (u > INT64_MAX)) overflow(aTHX_ out_of_bounds_error_s);
Branch: 2 branches
BranchTrueFalseTotal
if (may_die_on_overflow && (u > INT64_MAX)) overflow(aTHX_ out_of_bounds_error_s); 3 1 4
if (may_die_on_overflow && (u > INT64_MAX)) overflow(aTHX_ out_of_bounds_error_s); 2 1 3
279 3 return u;
280 }
281 else {
282 1112 return *(int64_t*)(&(SvI64Y(si64)));
283 }
284 }
285 }
286 2 method = gv_fetchmethod(stash, "as_int64");
287 2 ▶ if (method) {
Branch: 1 branch
BranchTrueFalseTotal
if (method) { 2 0 2
288 SV *result;
289 int count;
290 2 dSP;
291 2 ENTER;
292 2 SAVETMPS;
293 2 PUSHSTACKi(PERLSI_MAGIC);
294 2 ▶ PUSHMARK(SP);
Branch: 1 branch
BranchTrueFalseTotal
PUSHMARK(SP); 0 2 2
295 2 ▶ XPUSHs(sv);
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(sv); 0 2 2
296 2 PUTBACK;
297 2 count = perl_call_sv( (SV*)method, G_SCALAR );
298 2 SPAGAIN;
299 2 ▶ if (count != 1)
Branch: 1 branch
BranchTrueFalseTotal
if (count != 1) 0 2 2
300 0 Perl_croak(aTHX_ "internal error: method call returned %d values, 1 expected", count);
301 2 result = newSVsv(POPs);
302 2 PUTBACK;
303 2 POPSTACK;
304 2 SPAGAIN;
305 2 ▶ FREETMPS;
Branch: 1 branch
BranchTrueFalseTotal
FREETMPS; 2 0 2
306 2 LEAVE;
307 2 return SvI64(aTHX_ sv_2mortal(result));
308 }
309 }
310 }
311 else {
312 673 SvGETMAGIC(sv);
313 673 ▶ if (SvIOK(sv)) {
Branch: 1 branch
BranchTrueFalseTotal
if (SvIOK(sv)) { 585 88 673
314 585 ▶ if (SvIOK_UV(sv)) {
Branch: 1 branch
BranchTrueFalseTotal
if (SvIOK_UV(sv)) { 0 585 585
315 0 UV uv = SvUV(sv);
316 0 ▶ if (may_die_on_overflow &&
Branch: 1 branch
BranchTrueFalseTotal
if (may_die_on_overflow && 0 0 0
317 0 ▶ (uv > INT64_MAX)) overflow(aTHX_ out_of_bounds_error_s);
Branch: 1 branch
BranchTrueFalseTotal
(uv > INT64_MAX)) overflow(aTHX_ out_of_bounds_error_s); 0 0 0
318 0 return uv;
319 }
320 585 return SvIV(sv);
321 }
322 88 ▶ if (SvNOK(sv)) {
Branch: 1 branch
BranchTrueFalseTotal
if (SvNOK(sv)) { 16 72 88
323 16 NV nv = SvNV(sv);
324 16 ▶ if ( may_die_on_overflow &&
Branch: 2 branches
BranchTrueFalseTotal
if ( may_die_on_overflow && 13 3 16
if ( may_die_on_overflow && 7 6 13
325 13 ▶ ((nv >= NV_0x1p63) || (nv < -NV_0x1p63)) ) overflow(aTHX_ out_of_bounds_error_s);
Branch: 1 branch
BranchTrueFalseTotal
((nv >= NV_0x1p63) || (nv < -NV_0x1p63)) ) overflow(aTHX_ out_of_bounds_error_s); 4 3 7
326 11 return nv;
327 }
328 }
329 72 return strtoint64(aTHX_ SvPV_nolen(sv), 10, 1);
330 }
331  
332 static uint64_t
333 2654 SvU64(pTHX_ SV *sv) {
334 2654 ▶ if (SvROK(sv)) {
Branch: 1 branch
BranchTrueFalseTotal
if (SvROK(sv)) { 1028 1626 2654
335 1028 SV *su64 = SvRV(sv);
336 1028 ▶ if (su64 && SvOBJECT(su64)) {
Branch: 2 branches
BranchTrueFalseTotal
if (su64 && SvOBJECT(su64)) { 1028 0 1028
if (su64 && SvOBJECT(su64)) { 1028 0 1028
337 GV *method;
338 1028 HV *stash = SvSTASH(su64);
339 1028 ▶ char const * classname = HvNAME_get(stash);
Branch: 6 branches
BranchTrueFalseTotal
char const * classname = HvNAME_get(stash); 1028 0 1028
char const * classname = HvNAME_get(stash); 1028 0 1028
char const * classname = HvNAME_get(stash); 0 1028 1028
char const * classname = HvNAME_get(stash); 0 0 0
char const * classname = HvNAME_get(stash); 1028 0 1028
char const * classname = HvNAME_get(stash); 0 1028 1028
340 1028 ▶ if (memcmp(classname, "Math::", 6) == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (memcmp(classname, "Math::", 6) == 0) { 1026 2 1028
341 int u;
342 1026 ▶ if (classname[6] == 'U') {
Branch: 1 branch
BranchTrueFalseTotal
if (classname[6] == 'U') { 1025 1 1026
343 1025 u = 1;
344 1025 classname += 7;
345 }
346 else {
347 1 u = 0;
348 1 classname += 6;
349 }
350 1026 ▶ if (memcmp(classname, "Int64", 6) == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (memcmp(classname, "Int64", 6) == 0) { 1026 0 1026
351 1026 ▶ if (SvTYPE(su64) < SVt_I64)
Branch: 1 branch
BranchTrueFalseTotal
if (SvTYPE(su64) < SVt_I64) 0 1026 1026
352 0 ▶ Perl_croak(aTHX_ "Wrong internal representation for %s object", HvNAME_get(stash));
Branch: 6 branches
BranchTrueFalseTotal
Perl_croak(aTHX_ "Wrong internal representation for %s object", HvNAME_get(stash)); 0 0 0
Perl_croak(aTHX_ "Wrong internal representation for %s object", HvNAME_get(stash)); 0 0 0
Perl_croak(aTHX_ "Wrong internal representation for %s object", HvNAME_get(stash)); 0 0 0
Perl_croak(aTHX_ "Wrong internal representation for %s object", HvNAME_get(stash)); 0 0 0
Perl_croak(aTHX_ "Wrong internal representation for %s object", HvNAME_get(stash)); 0 0 0
Perl_croak(aTHX_ "Wrong internal representation for %s object", HvNAME_get(stash)); 0 0 0
353 1026 ▶ if (u) {
Branch: 1 branch
BranchTrueFalseTotal
if (u) { 1025 1 1026
354 1025 return *(uint64_t*)(&(SvI64Y(su64)));
355 }
356 else {
357 1 int64_t i = *(int64_t*)(&(SvI64Y(su64)));
358 1 ▶ if (may_die_on_overflow && (i < 0)) overflow(aTHX_ out_of_bounds_error_u);
Branch: 2 branches
BranchTrueFalseTotal
if (may_die_on_overflow && (i < 0)) overflow(aTHX_ out_of_bounds_error_u); 0 1 1
if (may_die_on_overflow && (i < 0)) overflow(aTHX_ out_of_bounds_error_u); 0 0 0
359 1 return i;
360 }
361 }
362 }
363 2 method = gv_fetchmethod(SvSTASH(su64), "as_uint64");
364 2 ▶ if (method) {
Branch: 1 branch
BranchTrueFalseTotal
if (method) { 2 0 2
365 SV *result;
366 int count;
367 2 dSP;
368 2 ENTER;
369 2 SAVETMPS;
370 2 PUSHSTACKi(PERLSI_MAGIC);
371 2 ▶ PUSHMARK(SP);
Branch: 1 branch
BranchTrueFalseTotal
PUSHMARK(SP); 0 2 2
372 2 ▶ XPUSHs(sv);
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(sv); 0 2 2
373 2 PUTBACK;
374 2 count = perl_call_sv( (SV*)method, G_SCALAR );
375 2 SPAGAIN;
376 2 ▶ if (count != 1)
Branch: 1 branch
BranchTrueFalseTotal
if (count != 1) 0 2 2
377 0 Perl_croak(aTHX_ "internal error: method call returned %d values, 1 expected", count);
378 2 result = newSVsv(POPs);
379 2 PUTBACK;
380 2 POPSTACK;
381 2 SPAGAIN;
382 2 ▶ FREETMPS;
Branch: 1 branch
BranchTrueFalseTotal
FREETMPS; 2 0 2
383 2 LEAVE;
384 2 return SvU64(aTHX_ sv_2mortal(result));
385 }
386 }
387 }
388 else {
389 1626 SvGETMAGIC(sv);
390 1626 ▶ if (SvIOK(sv)) {
Branch: 1 branch
BranchTrueFalseTotal
if (SvIOK(sv)) { 1558 68 1626
391 1558 ▶ if (SvIOK_UV(sv)) {
Branch: 1 branch
BranchTrueFalseTotal
if (SvIOK_UV(sv)) { 3 1555 1558
392 3 return SvUV(sv);
393 }
394 else {
395 1555 IV iv = SvIV(sv);
396 1555 ▶ if (may_die_on_overflow &&
Branch: 2 branches
BranchTrueFalseTotal
if (may_die_on_overflow && 35 1520 1555
if (may_die_on_overflow && 2 33 35
397 2 (iv < 0) ) overflow(aTHX_ out_of_bounds_error_u);
398 1554 return SvIV(sv);
399 }
400 }
401 68 ▶ if (SvNOK(sv)) {
Branch: 1 branch
BranchTrueFalseTotal
if (SvNOK(sv)) { 5 63 68
402 5 NV nv = SvNV(sv);
403 5 ▶ if (may_die_on_overflow &&
Branch: 2 branches
BranchTrueFalseTotal
if (may_die_on_overflow && 5 0 5
if (may_die_on_overflow && 5 0 5
404 5 ▶ ( (nv < 0) || (nv >= NV_0x1p64)) ) overflow(aTHX_ out_of_bounds_error_u);
Branch: 1 branch
BranchTrueFalseTotal
( (nv < 0) || (nv >= NV_0x1p64)) ) overflow(aTHX_ out_of_bounds_error_u); 4 1 5
405 3 return NV2U64(nv);
406 }
407 }
408 63 return strtoint64(aTHX_ SvPV_nolen(sv), 10, 0);
409 }
410  
411 static SV *
412 1 si64_to_number(pTHX_ SV *sv) {
413 1 int64_t i64 = SvI64(aTHX_ sv);
414 1 ▶ if (i64 < 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (i64 < 0) { 0 1 1
415 0 IV iv = i64;
416 0 ▶ if (iv == i64)
Branch: 1 branch
BranchTrueFalseTotal
if (iv == i64) 0 0 0
417 0 return newSViv(iv);
418 }
419 else {
420 1 UV uv = i64;
421 1 ▶ if (uv == i64)
Branch: 1 branch
BranchTrueFalseTotal
if (uv == i64) 1 0 1
422 1 return newSVuv(uv);
423 }
424 0 return newSVnv(i64);
425 }
426  
427 static SV *
428 2 su64_to_number(pTHX_ SV *sv) {
429 2 uint64_t u64 = SvU64(aTHX_ sv);
430 2 UV uv = u64;
431 2 ▶ if (uv == u64)
Branch: 1 branch
BranchTrueFalseTotal
if (uv == u64) 2 0 2
432 2 return newSVuv(uv);
433 0 return newSVnv(U642NV(u64));
434 }
435  
436 #define I64STRLEN 65
437  
438 static SV *
439 4437 u64_to_string_with_sign(pTHX_ uint64_t u64, int base, int sign) {
440 char str[I64STRLEN];
441 4437 int len = 0;
442 4437 ▶ if ((base > 36) || (base < 2))
Branch: 2 branches
BranchTrueFalseTotal
if ((base > 36) || (base < 2)) 4437 0 4437
if ((base > 36) || (base < 2)) 0 4437 4437
443 0 Perl_croak(aTHX_ "base %d out of range [2,36]", base);
444 74455 ▶ while (u64) {
Branch: 1 branch
BranchTrueFalseTotal
while (u64) { 70018 4437 74455
445 70018 char c = u64 % base;
446 70018 u64 /= base;
447 70018 ▶ str[len++] = c + (c > 9 ? 'A' - 10 : '0');
Branch: 1 branch
BranchTrueFalseTotal
str[len++] = c + (c > 9 ? 'A' - 10 : '0'); 3965 66053 70018
448 }
449 4437 ▶ if (len) {
Branch: 1 branch
BranchTrueFalseTotal
if (len) { 4432 5 4437
450 int i;
451 4432 int svlen = len + (sign ? 1 : 0);
452 4432 SV *sv = newSV(svlen);
453 4432 char *pv = SvPVX(sv);
454 4432 SvPOK_on(sv);
455 4432 SvCUR_set(sv, svlen);
456 4432 ▶ if (sign) *(pv++) = '-';
Branch: 1 branch
BranchTrueFalseTotal
if (sign) *(pv++) = '-'; 645 3787 4432
457 74450 ▶ for (i = len; i--;) *(pv++) = str[i];
Branch: 1 branch
BranchTrueFalseTotal
for (i = len; i--;) *(pv++) = str[i]; 70018 4432 74450
458 4432 *pv = '\0';
459 4432 return sv;
460 }
461 else {
462 5 return newSVpvs("0");
463 }
464 }
465  
466 static SV *
467 2306 i64_to_string(pTHX_ int64_t i64, int base) {
468 2306 ▶ if (i64 < 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (i64 < 0) { 645 1661 2306
469 645 return u64_to_string_with_sign(aTHX_ -i64, base, 1);
470 }
471 1661 return u64_to_string_with_sign(aTHX_ i64, base, 0);
472 }
473  
474 static uint64_t
475 0 randU64(pTHX) {
476 dMY_CXT;
477 0 return rand64(&(MY_CXT.is));
478 }
479  
480 static void
481 8 mul_check_overflow(pTHX_ uint64_t a, uint64_t b, const char *error_str) {
482 8 ▶ if (a < b) {
Branch: 1 branch
BranchTrueFalseTotal
if (a < b) { 3 5 8
483 3 uint64_t tmp = a;
484 3 a = b; b = tmp;
485 }
486 8 ▶ if (b > UINT32_MAX) overflow(aTHX_ error_str);
Branch: 1 branch
BranchTrueFalseTotal
if (b > UINT32_MAX) overflow(aTHX_ error_str); 2 6 8
487 else {
488 uint64_t rl, rh;
489 6 rl = (a & UINT32_MAX) * b;
490 6 rh = (a >> 32) * b + (rl >> 32);
491 6 ▶ if (rh > UINT32_MAX) overflow(aTHX_ error_str);
Branch: 1 branch
BranchTrueFalseTotal
if (rh > UINT32_MAX) overflow(aTHX_ error_str); 3 3 6
492 }
493 5 }
494  
495 static uint64_t
496 558 powU64(pTHX_ uint64_t a, uint64_t b) {
497 uint64_t r;
498 558 int mdoo = may_die_on_overflow;
499 558 ▶ if (b == 0) return 1;
Branch: 1 branch
BranchTrueFalseTotal
if (b == 0) return 1; 16 542 558
500 542 ▶ if (b == 1) return a;
Branch: 1 branch
BranchTrueFalseTotal
if (b == 1) return a; 13 529 542
501 529 ▶ if (b == 2) {
Branch: 1 branch
BranchTrueFalseTotal
if (b == 2) { 14 515 529
502 14 ▶ if (mdoo && (a > UINT32_MAX)) overflow(aTHX_ pow_error);
Branch: 2 branches
BranchTrueFalseTotal
if (mdoo && (a > UINT32_MAX)) overflow(aTHX_ pow_error); 0 14 14
if (mdoo && (a > UINT32_MAX)) overflow(aTHX_ pow_error); 0 0 0
503 14 return a*a;
504 }
505 515 ▶ if (a == 0) return 0;
Branch: 1 branch
BranchTrueFalseTotal
if (a == 0) return 0; 2 513 515
506 513 ▶ if (a == 1) return 1;
Branch: 1 branch
BranchTrueFalseTotal
if (a == 1) return 1; 4 509 513
507 509 ▶ if (a == 2) {
Branch: 1 branch
BranchTrueFalseTotal
if (a == 2) { 442 67 509
508 442 ▶ if (b > 63) {
Branch: 1 branch
BranchTrueFalseTotal
if (b > 63) { 2 440 442
509 2 ▶ if (mdoo) overflow(aTHX_ pow_error);
Branch: 1 branch
BranchTrueFalseTotal
if (mdoo) overflow(aTHX_ pow_error); 1 1 2
510 1 return 0;
511 }
512 440 return (((uint64_t)1) << b);
513 }
514 67 ▶ if (mdoo) {
Branch: 1 branch
BranchTrueFalseTotal
if (mdoo) { 2 65 67
515 2 ▶ r = ((b & 1) ? a : 1);
Branch: 1 branch
BranchTrueFalseTotal
r = ((b & 1) ? a : 1); 2 0 2
516 3 ▶ while ((b >>= 1)) {
Branch: 1 branch
BranchTrueFalseTotal
while ((b >>= 1)) { 2 1 3
517 2 ▶ if (a > UINT32_MAX) overflow(aTHX_ pow_error);
Branch: 1 branch
BranchTrueFalseTotal
if (a > UINT32_MAX) overflow(aTHX_ pow_error); 0 2 2
518 2 a *= a;
519 2 ▶ if (b & 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (b & 1) { 2 0 2
520 2 mul_check_overflow(aTHX_ r, a, pow_error);
521 1 r *= a;
522 }
523 }
524 }
525 else {
526 65 r = 1;
527 396 ▶ while (b) {
Branch: 1 branch
BranchTrueFalseTotal
while (b) { 331 65 396
528 331 ▶ if (b & 1) r *= a;
Branch: 1 branch
BranchTrueFalseTotal
if (b & 1) r *= a; 232 99 331
529 331 a *= a;
530 331 b >>= 1;
531 }
532 }
533 66 return r;
534 }
535  
536 static SV *
537 359 uint64_to_BER(pTHX_ uint64_t a) {
538 char buffer[10];
539 359 char *top = buffer + sizeof(buffer);
540 359 char *p = top;
541 359 *(--p) = (a & 0x7f);
542 3396 ▶ while ((a >>= 7)) {
Branch: 1 branch
BranchTrueFalseTotal
while ((a >>= 7)) { 3037 359 3396
543 3037 *(--p) = (a & 0x7f) | 0x80;
544  
545 }
546 359 return newSVpvn(p, top - p);
547 }
548  
549 static SV *
550 208 int64_to_BER(pTHX_ int64_t a) {
551 416 ▶ return uint64_to_BER(aTHX_
Branch: 1 branch
BranchTrueFalseTotal
return uint64_to_BER(aTHX_ 93 115 208
552 a < 0
553 93 ? ( ( ( ~(uint64_t)a) << 1 ) | 1 )
554 115 : ( ( ( (uint64_t)a) << 1 ) | 0 ) );
555 }
556  
557 static uint64_t
558 357 BER_to_uint64(pTHX_ SV *sv) {
559 STRLEN len;
560 357 char *pv = SvPVbyte(sv, len);
561 uint64_t a;
562 IV i;
563 3378 ▶ for (i = 0, a = 0; i < len; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0, a = 0; i < len; i++) { 3378 0 3378
564 3378 ▶ if (may_die_on_overflow && (a > (((uint64_t)1) << (63 - 7))))
Branch: 2 branches
BranchTrueFalseTotal
if (may_die_on_overflow && (a > (((uint64_t)1) << (63 - 7)))) 0 3378 3378
if (may_die_on_overflow && (a > (((uint64_t)1) << (63 - 7)))) 0 0 0
565 0 overflow(aTHX_ out_of_bounds_error_u);
566 3378 a = (a << 7) | (pv[i] & 0x7f);
567 3378 ▶ if ((pv[i] & 0x80) == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ((pv[i] & 0x80) == 0) { 357 3021 3378
568 357 ▶ if (i + 1 != len) croak_string(aTHX_ invalid_BER_error);
Branch: 1 branch
BranchTrueFalseTotal
if (i + 1 != len) croak_string(aTHX_ invalid_BER_error); 0 357 357
569 357 return a;
570 }
571 }
572 0 croak_string(aTHX_ invalid_BER_error);
573 0 return 0; /* this dead code is a workaround for OpenWatcom */
574 }
575  
576 static int64_t
577 207 BER_to_int64(pTHX_ SV *sv) {
578 207 uint64_t a = BER_to_uint64(aTHX_ sv);
579 207 int64_t b = (int64_t)(a >> 1);
580 207 ▶ return (a & 1 ? ~b : b);
Branch: 1 branch
BranchTrueFalseTotal
return (a & 1 ? ~b : b); 93 114 207
581 }
582  
583 static IV
584 106 BER_length(pTHX_ SV *sv) {
585 STRLEN len;
586 106 char *pv = SvPVbyte(sv, len);
587 IV i;
588 998 ▶ for (i = 0; i < len; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < len; i++) { 998 0 998
589 998 ▶ if ((pv[i] & 0x80) == 0) return i + 1;
Branch: 1 branch
BranchTrueFalseTotal
if ((pv[i] & 0x80) == 0) return i + 1; 106 892 998
590 }
591 0 return -1;
592 }
593  
594 #include "c_api.h"
595  
596 MODULE = Math::Int64 PACKAGE = Math::Int64 PREFIX=miu64_
597 PROTOTYPES: DISABLE
598  
599 BOOT:
600 {
601 MY_CXT_INIT;
602 13 randinit(&(MY_CXT.is), 0);
603 13 may_die_on_overflow = 0;
604 13 may_use_native = 0;
605 13 INIT_C_API;
606 }
607  
608 char *
609 miu64__backend()
610 CODE:
611 5 RETVAL = BACKEND;
612 OUTPUT:
613 RETVAL
614  
615 void
616 miu64__set_may_die_on_overflow(v)
617 int v
618 CODE:
619 1 may_die_on_overflow = v;
620  
621 void
622 miu64__set_may_use_native(v)
623 int v;
624 CODE:
625 2 may_use_native = v;
626  
627 SV *
628 miu64_int64(value=&PL_sv_undef)
629 SV *value;
630 CODE:
631 243 ▶ RETVAL = (use_native
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = (use_native 4 0 4
632 4 ? newSViv(SvIV(value))
633 249 ▶ : newSVi64(aTHX_ SvI64(aTHX_ value)));
Branch: 1 branch
BranchTrueFalseTotal
: newSVi64(aTHX_ SvI64(aTHX_ value))); 4 245 249
634 OUTPUT:
635 RETVAL
636  
637 SV *
638 miu64_uint64(value=&PL_sv_undef)
639 SV *value;
640 CODE:
641 276 ▶ RETVAL = (use_native
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = (use_native 3 0 3
642 3 ? newSVuv(SvUV(value))
643 280 ▶ : newSVu64(aTHX_ SvU64(aTHX_ value)));
Branch: 1 branch
BranchTrueFalseTotal
: newSVu64(aTHX_ SvU64(aTHX_ value))); 3 277 280
644 OUTPUT:
645 RETVAL
646  
647 SV *
648 miu64_int64_to_number(self)
649 SV *self
650 CODE:
651 0 RETVAL = si64_to_number(aTHX_ self);
652 OUTPUT:
653 RETVAL
654  
655 SV *
656 miu64_uint64_to_number(self)
657 SV *self
658 CODE:
659 1 RETVAL = su64_to_number(aTHX_ self);
660 OUTPUT:
661 RETVAL
662  
663 SV *
664 miu64_net_to_int64(net)
665 SV *net;
666 PREINIT:
667 STRLEN len;
668 58 unsigned char *pv = (unsigned char *)SvPVbyte(net, len);
669 int64_t i64;
670 CODE:
671 58 ▶ if (len != 8) croak_string(aTHX_ invalid_length_error_s);
Branch: 1 branch
BranchTrueFalseTotal
if (len != 8) croak_string(aTHX_ invalid_length_error_s); 0 58 58
672 58 i64 = (((((((((((((((int64_t)pv[0]) << 8)
673 58 + (int64_t)pv[1]) << 8)
674 58 + (int64_t)pv[2]) << 8)
675 58 + (int64_t)pv[3]) << 8)
676 58 + (int64_t)pv[4]) << 8)
677 58 + (int64_t)pv[5]) << 8)
678 58 + (int64_t)pv[6]) <<8)
679 58 + (int64_t)pv[7];
680 61 ▶ RETVAL = ( use_native
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = ( use_native 3 0 3
681 3 ? newSViv(i64)
682 58 ▶ : newSVi64(aTHX_ i64) );
Branch: 1 branch
BranchTrueFalseTotal
: newSVi64(aTHX_ i64) ); 3 55 58
683 OUTPUT:
684 RETVAL
685  
686 SV *
687 miu64_net_to_uint64(net)
688 SV *net;
689 PREINIT:
690 STRLEN len;
691 56 unsigned char *pv = (unsigned char *)SvPVbyte(net, len);
692 uint64_t u64;
693 CODE:
694 56 ▶ if (len != 8)
Branch: 1 branch
BranchTrueFalseTotal
if (len != 8) 0 56 56
695 0 croak_string(aTHX_ invalid_length_error_u);
696 56 u64 = (((((((((((((((uint64_t)pv[0]) << 8)
697 56 + (uint64_t)pv[1]) << 8)
698 56 + (uint64_t)pv[2]) << 8)
699 56 + (uint64_t)pv[3]) << 8)
700 56 + (uint64_t)pv[4]) << 8)
701 56 + (uint64_t)pv[5]) << 8)
702 56 + (uint64_t)pv[6]) <<8)
703 56 + (uint64_t)pv[7];
704 56 ▶ RETVAL = ( use_native
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = ( use_native 0 0 0
705 0 ? newSVuv(u64)
706 56 ▶ : newSVu64(aTHX_ u64) );
Branch: 1 branch
BranchTrueFalseTotal
: newSVu64(aTHX_ u64) ); 0 56 56
707 OUTPUT:
708 RETVAL
709  
710 SV *
711 miu64_int64_to_net(self)
712 SV *self
713 PREINIT:
714 char *pv;
715 56 int64_t i64 = SvI64(aTHX_ self);
716 int i;
717 CODE:
718 56 RETVAL = newSV(8);
719 56 SvPOK_on(RETVAL);
720 56 SvCUR_set(RETVAL, 8);
721 56 pv = SvPVX(RETVAL);
722 56 pv[8] = '\0';
723 504 ▶ for (i = 7; i >= 0; i--, i64 >>= 8)
Branch: 1 branch
BranchTrueFalseTotal
for (i = 7; i >= 0; i--, i64 >>= 8) 448 56 504
724 448 pv[i] = i64;
725 OUTPUT:
726 RETVAL
727  
728 SV *
729 miu64_uint64_to_net(self)
730 SV *self
731 PREINIT:
732 char *pv;
733 56 uint64_t u64 = SvU64(aTHX_ self);
734 int i;
735 CODE:
736 56 RETVAL = newSV(8);
737 56 SvPOK_on(RETVAL);
738 56 SvCUR_set(RETVAL, 8);
739 56 pv = SvPVX(RETVAL);
740 56 pv[8] = '\0';
741 504 ▶ for (i = 7; i >= 0; i--, u64 >>= 8)
Branch: 1 branch
BranchTrueFalseTotal
for (i = 7; i >= 0; i--, u64 >>= 8) 448 56 504
742 448 pv[i] = u64;
743 OUTPUT:
744 RETVAL
745  
746 SV *
747 miu64_BER_to_int64(ber)
748 SV *ber
749 CODE:
750 107 RETVAL = newSVi64(aTHX_ BER_to_int64(aTHX_ ber));
751 OUTPUT:
752 RETVAL
753  
754 SV *
755 miu64_BER_to_uint64(ber)
756 SV *ber
757 CODE:
758 50 RETVAL = newSVu64(aTHX_ BER_to_uint64(aTHX_ ber));
759 OUTPUT:
760 RETVAL
761  
762 SV *
763 miu64_int64_to_BER(self)
764 SV *self
765 CODE:
766 108 RETVAL = int64_to_BER(aTHX_ SvI64(aTHX_ self));
767 OUTPUT:
768 RETVAL
769  
770 SV *
771 miu64_uint64_to_BER(self)
772 SV *self
773 CODE:
774 51 RETVAL = uint64_to_BER(aTHX_ SvU64(aTHX_ self));
775 OUTPUT:
776 RETVAL
777  
778 SV *
779 miu64_native_to_int64(native)
780 SV *native
781 PREINIT:
782 STRLEN len;
783 62 char *pv = SvPVbyte(native, len);
784 CODE:
785 62 ▶ if (len != 8)
Branch: 1 branch
BranchTrueFalseTotal
if (len != 8) 0 62 62
786 0 croak_string(aTHX_ invalid_length_error_s);
787 62 ▶ if (use_native) {
Branch: 2 branches
BranchTrueFalseTotal
if (use_native) { 6 56 62
if (use_native) { 6 0 6
788 6 RETVAL = newSViv(0);
789 6 Copy(pv, &(SvIVX(RETVAL)), 8, char);
790 }
791 else {
792 56 RETVAL = newSVi64(aTHX_ 0);
793 56 Copy(pv, &(SvI64X(RETVAL)), 8, char);
794 }
795 OUTPUT:
796 RETVAL
797  
798 SV *
799 BER_length(sv)
800 SV *sv
801 PREINIT:
802 IV len;
803 CODE:
804 106 len = BER_length(aTHX_ sv);
805 106 ▶ RETVAL = (len < 0 ? &PL_sv_undef : newSViv(len));
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = (len < 0 ? &PL_sv_undef : newSViv(len)); 106 0 106
806 OUTPUT:
807 RETVAL
808  
809 SV *
810 miu64_native_to_uint64(native)
811 SV *native
812 PREINIT:
813 STRLEN len;
814 56 char *pv = SvPVbyte(native, len);
815 CODE:
816 56 ▶ if (len != 8)
Branch: 1 branch
BranchTrueFalseTotal
if (len != 8) 0 56 56
817 0 croak_string(aTHX_ invalid_length_error_u);
818 56 ▶ if (use_native) {
Branch: 2 branches
BranchTrueFalseTotal
if (use_native) { 0 56 56
if (use_native) { 0 0 0
819 uint64_t tmp;
820 0 Copy(pv, &tmp, 8, char);
821 0 RETVAL = newSVuv(tmp);
822 }
823 else {
824 56 RETVAL = newSVu64(aTHX_ 0);
825 56 Copy(pv, &(SvU64X(RETVAL)), 8, char);
826 }
827 OUTPUT:
828 RETVAL
829  
830 SV *
831 miu64_int64_to_native(self)
832 SV *self
833 PREINIT:
834 char *pv;
835 62 int64_t i64 = SvI64(aTHX_ self);
836 CODE:
837 62 RETVAL = newSV(9);
838 62 SvPOK_on(RETVAL);
839 62 SvCUR_set(RETVAL, 8);
840 62 pv = SvPVX(RETVAL);
841 62 Copy(&i64, pv, 8, char);
842 62 pv[8] = '\0';
843 OUTPUT:
844 RETVAL
845  
846 SV *
847 miu64_uint64_to_native(self)
848 SV *self
849 PREINIT:
850 char *pv;
851 56 uint64_t u64 = SvU64(aTHX_ self);
852 CODE:
853 56 RETVAL = newSV(9);
854 56 SvPOK_on(RETVAL);
855 56 SvCUR_set(RETVAL, 8);
856 56 pv = SvPVX(RETVAL);
857 56 Copy(&u64, pv, 8, char);
858 56 pv[8] = '\0';
859 OUTPUT:
860 RETVAL
861  
862 SV *
863 miu64_int64_to_string(self, base = 10)
864 SV *self
865 int base
866 CODE:
867 318 RETVAL = i64_to_string(aTHX_ SvI64(aTHX_ self), base);
868 OUTPUT:
869 RETVAL
870  
871 SV *
872 miu64_uint64_to_string(self, base = 10)
873 SV *self
874 int base
875 CODE:
876 300 RETVAL = u64_to_string_with_sign(aTHX_ SvU64(aTHX_ self), base, 0);
877 OUTPUT:
878 RETVAL
879  
880 SV *
881 miu64_int64_to_hex(self)
882 SV *self
883 CODE:
884 212 RETVAL = i64_to_string(aTHX_ SvI64(aTHX_ self), 16);
885 OUTPUT:
886 RETVAL
887  
888 SV *
889 miu64_uint64_to_hex(self)
890 SV *self
891 CODE:
892 200 RETVAL = u64_to_string_with_sign(aTHX_ SvU64(aTHX_ self), 16, 0);
893 OUTPUT:
894 RETVAL
895  
896 SV *
897 miu64_string_to_int64(str, base = 0)
898 const char *str;
899 int base;
900 CODE:
901 352 ▶ RETVAL = ( use_native
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = ( use_native 0 0 0
902 0 ? newSViv(strtoint64(aTHX_ str, base, 1))
903 352 ▶ : newSVi64(aTHX_ strtoint64(aTHX_ str, base, 1)) );
Branch: 1 branch
BranchTrueFalseTotal
: newSVi64(aTHX_ strtoint64(aTHX_ str, base, 1)) ); 0 352 352
904 OUTPUT:
905 RETVAL
906  
907 SV *
908 miu64_string_to_uint64(str, base = 0)
909 const char *str;
910 int base;
911 CODE:
912 319 ▶ RETVAL = ( use_native
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = ( use_native 0 0 0
913 0 ? newSVuv(strtoint64(aTHX_ str, base, 0))
914 319 ▶ : newSVu64(aTHX_ strtoint64(aTHX_ str, base, 0)) );
Branch: 1 branch
BranchTrueFalseTotal
: newSVu64(aTHX_ strtoint64(aTHX_ str, base, 0)) ); 0 319 319
915 OUTPUT:
916 RETVAL
917  
918 SV *
919 miu64_hex_to_int64(str)
920 const char *str;
921 CODE:
922 53 ▶ RETVAL = ( use_native
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = ( use_native 0 0 0
923 0 ? newSViv(strtoint64(aTHX_ str, 16, 1))
924 53 ▶ : newSVi64(aTHX_ strtoint64(aTHX_ str, 16, 1)) );
Branch: 1 branch
BranchTrueFalseTotal
: newSVi64(aTHX_ strtoint64(aTHX_ str, 16, 1)) ); 0 53 53
925 OUTPUT:
926 RETVAL
927  
928 SV *
929 miu64_hex_to_uint64(str)
930 const char *str;
931 CODE:
932 50 ▶ RETVAL = ( use_native
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = ( use_native 0 0 0
933 0 ? newSVuv(strtoint64(aTHX_ str, 16, 0))
934 50 ▶ : newSVu64(aTHX_ strtoint64(aTHX_ str, 16, 0)) );
Branch: 1 branch
BranchTrueFalseTotal
: newSVu64(aTHX_ strtoint64(aTHX_ str, 16, 0)) ); 0 50 50
935 OUTPUT:
936 RETVAL
937  
938  
939 SV *
940 miu64_int64_rand()
941 PREINIT:
942 dMY_CXT;
943 150 int64_t i64 = rand64(&(MY_CXT.is));
944 CODE:
945 150 ▶ RETVAL = ( use_native
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = ( use_native 0 0 0
946 0 ? newSViv(i64)
947 150 ▶ : newSVi64(aTHX_ i64) );
Branch: 1 branch
BranchTrueFalseTotal
: newSVi64(aTHX_ i64) ); 0 150 150
948 OUTPUT:
949 RETVAL
950  
951 SV *
952 miu64_uint64_rand()
953 PREINIT:
954 dMY_CXT;
955 150 uint64_t u64 = rand64(&(MY_CXT.is));
956 CODE:
957 150 ▶ RETVAL = ( use_native
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = ( use_native 0 0 0
958 0 ? newSViv(u64)
959 150 ▶ : newSVu64(aTHX_ u64) );
Branch: 1 branch
BranchTrueFalseTotal
: newSVu64(aTHX_ u64) ); 0 150 150
960 OUTPUT:
961 RETVAL
962  
963 void
964 miu64_int64_srand(seed=&PL_sv_undef)
965 SV *seed
966 PREINIT:
967 dMY_CXT;
968 isaac64_state_t *is;
969 CODE:
970 0 is = &(MY_CXT.is);
971 0 ▶ if (SvOK(seed) && SvCUR(seed)) {
Branch: 2 branches
BranchTrueFalseTotal
if (SvOK(seed) && SvCUR(seed)) { 0 0 0
if (SvOK(seed) && SvCUR(seed)) { 0 0 0
972 STRLEN len;
973 0 const char *pv = SvPV_const(seed, len);
974 0 char *shadow = (char*)is->randrsl;
975 int i;
976 0 ▶ if (len > sizeof(is->randrsl)) len = sizeof(is->randrsl);
Branch: 1 branch
BranchTrueFalseTotal
if (len > sizeof(is->randrsl)) len = sizeof(is->randrsl); 0 0 0
977 0 Zero(shadow, sizeof(is->randrsl), char);
978 0 Copy(pv, shadow, len, char);
979  
980 /* make the seed endianness agnostic */
981 0 ▶ for (i = 0; i < RANDSIZ; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < RANDSIZ; i++) { 0 0 0
982 0 char *p = shadow + i * sizeof(uint64_t);
983 0 is->randrsl[i] = (((((((((((((((uint64_t)p[0]) << 8) + p[1]) << 8) + p[2]) << 8) + p[3]) << 8) +
984 0 p[4]) << 8) + p[5]) << 8) + p[6]) << 8) + p[7];
985 }
986 0 randinit(is, 1);
987 }
988 else
989 0 randinit(is, 0);
990  
991 MODULE = Math::Int64 PACKAGE = Math::Int64 PREFIX=mi64
992 PROTOTYPES: DISABLE
993  
994 SV *
995 mi64_inc(self, other = NULL, rev = NULL)
996 SV *self
997 SV *other = NO_INIT
998 SV *rev = NO_INIT
999 CODE:
1000 2 ▶ if (may_die_on_overflow && (SvI64x(self) == INT64_MAX)) overflow(aTHX_ inc_error);
Branch: 2 branches
BranchTrueFalseTotal
if (may_die_on_overflow && (SvI64x(self) == INT64_MAX)) overflow(aTHX_ inc_error); 2 0 2
if (may_die_on_overflow && (SvI64x(self) == INT64_MAX)) overflow(aTHX_ inc_error); 2 0 2
1001 1 SvI64x(self)++;
1002 1 RETVAL = self;
1003 1 SvREFCNT_inc(RETVAL);
1004 OUTPUT:
1005 RETVAL
1006  
1007 SV *
1008 mi64_dec(self, other = NULL, rev = NULL)
1009 SV *self
1010 SV *other = NO_INIT
1011 SV *rev = NO_INIT
1012 CODE:
1013 2 ▶ if (may_die_on_overflow && (SvI64x(self) == INT64_MIN)) overflow(aTHX_ dec_error);
Branch: 2 branches
BranchTrueFalseTotal
if (may_die_on_overflow && (SvI64x(self) == INT64_MIN)) overflow(aTHX_ dec_error); 2 0 2
if (may_die_on_overflow && (SvI64x(self) == INT64_MIN)) overflow(aTHX_ dec_error); 2 0 2
1014 1 SvI64x(self)--;
1015 1 RETVAL = self;
1016 1 SvREFCNT_inc(RETVAL);
1017 OUTPUT:
1018 RETVAL
1019  
1020 SV *
1021 mi64_add(self, other, rev = &PL_sv_no)
1022 SV *self
1023 SV *other
1024 SV *rev
1025 PREINIT:
1026 13 int64_t a = SvI64x(self);
1027 13 int64_t b = SvI64(aTHX_ other);
1028 CODE:
1029 15 ▶ if ( may_die_on_overflow &&
Branch: 3 branches
BranchTrueFalseTotal
if ( may_die_on_overflow && 2 11 13
if ( may_die_on_overflow && 2 0 2
if ( may_die_on_overflow && 2 0 2
1030 ( a > 0
1031 2 ▶ ? ( (b > 0) && (INT64_MAX - a < b) )
Branch: 2 branches
BranchTrueFalseTotal
? ( (b > 0) && (INT64_MAX - a < b) ) 2 0 2
? ( (b > 0) && (INT64_MAX - a < b) ) 2 0 2
1032 2 ▶ : ( (b < 0) && (INT64_MIN - a > b) ) ) ) overflow(aTHX_ add_error);
Branch: 2 branches
BranchTrueFalseTotal
: ( (b < 0) && (INT64_MIN - a > b) ) ) ) overflow(aTHX_ add_error); 0 0 0
: ( (b < 0) && (INT64_MIN - a > b) ) ) ) overflow(aTHX_ add_error); 0 0 0
1033 12 ▶ if (SvOK(rev))
Branch: 1 branch
BranchTrueFalseTotal
if (SvOK(rev)) 11 1 12
1034 11 RETVAL = newSVi64(aTHX_ a + b);
1035 else {
1036 1 RETVAL = self;
1037 1 SvREFCNT_inc(RETVAL);
1038 1 SvI64x(self) = a + b;
1039 }
1040 OUTPUT:
1041 RETVAL
1042  
1043 SV *
1044 mi64_sub(self, other, rev = &PL_sv_no)
1045 SV *self
1046 SV *other
1047 SV *rev
1048 PREINIT:
1049 10 int64_t a = SvI64x(self);
1050 10 int64_t b = SvI64(aTHX_ other);
1051 CODE:
1052 10 ▶ if (SvTRUE(rev)) {
Branch: 1 branch
BranchTrueFalseTotal
if (SvTRUE(rev)) { 0 10 10
1053 0 int64_t tmp = a;
1054 0 a = b; b = tmp;
1055 }
1056 12 ▶ if ( may_die_on_overflow &&
Branch: 3 branches
BranchTrueFalseTotal
if ( may_die_on_overflow && 2 8 10
if ( may_die_on_overflow && 0 2 2
if ( may_die_on_overflow && 2 0 2
1057 ( a > 0
1058 0 ▶ ? ( ( b < 0) && (a - INT64_MAX > b) )
Branch: 2 branches
BranchTrueFalseTotal
? ( ( b < 0) && (a - INT64_MAX > b) ) 0 0 0
? ( ( b < 0) && (a - INT64_MAX > b) ) 0 0 0
1059 4 ▶ : ( ( b > 0) && (a - INT64_MIN < b) ) ) ) overflow(aTHX_ sub_error);
Branch: 2 branches
BranchTrueFalseTotal
: ( ( b > 0) && (a - INT64_MIN < b) ) ) ) overflow(aTHX_ sub_error); 2 0 2
: ( ( b > 0) && (a - INT64_MIN < b) ) ) ) overflow(aTHX_ sub_error); 2 0 2
1060 9 ▶ if (SvOK(rev))
Branch: 1 branch
BranchTrueFalseTotal
if (SvOK(rev)) 8 1 9
1061 8 RETVAL = newSVi64(aTHX_ a - b);
1062 else {
1063 1 RETVAL = self;
1064 1 SvREFCNT_inc(RETVAL);
1065 1 SvI64x(self) = a - b;
1066 }
1067 OUTPUT:
1068 RETVAL
1069  
1070 SV *
1071 mi64_mul(self, other, rev = &PL_sv_no)
1072 SV *self
1073 SV *other
1074 SV *rev
1075 PREINIT:
1076 13 int64_t a1 = SvI64x(self);
1077 13 int64_t b1 = SvI64(aTHX_ other);
1078 CODE:
1079 13 ▶ if (may_die_on_overflow) {
Branch: 1 branch
BranchTrueFalseTotal
if (may_die_on_overflow) { 0 13 13
1080 0 int neg = 0;
1081 uint64_t a, b;
1082 0 ▶ if (a1 < 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (a1 < 0) { 0 0 0
1083 0 a = -a1;
1084 0 neg ^= 1;
1085 }
1086 0 else a = a1;
1087 0 ▶ if (b1 < 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (b1 < 0) { 0 0 0
1088 0 b = -b1;
1089 0 neg ^= 1;
1090 }
1091 0 else b = b1;
1092 0 mul_check_overflow(aTHX_ a, b, mul_error);
1093 0 ▶ if (a * b > (neg ? (~(uint64_t)INT64_MIN + 1) : INT64_MAX)) overflow(aTHX_ mul_error);
Branch: 2 branches
BranchTrueFalseTotal
if (a * b > (neg ? (~(uint64_t)INT64_MIN + 1) : INT64_MAX)) overflow(aTHX_ mul_error); 0 0 0
if (a * b > (neg ? (~(uint64_t)INT64_MIN + 1) : INT64_MAX)) overflow(aTHX_ mul_error); 0 0 0
1094 }
1095 13 ▶ if (SvOK(rev))
Branch: 1 branch
BranchTrueFalseTotal
if (SvOK(rev)) 12 1 13
1096 12 RETVAL = newSVi64(aTHX_ a1 * b1);
1097 else {
1098 1 RETVAL = self;
1099 1 SvREFCNT_inc(RETVAL);
1100 1 SvI64x(self) = a1 * b1;
1101 }
1102 OUTPUT:
1103 RETVAL
1104  
1105 SV *
1106 mi64_div(self, other, rev = &PL_sv_no)
1107 SV *self
1108 SV *other
1109 SV *rev
1110 PREINIT:
1111 int64_t up;
1112 int64_t down;
1113 CODE:
1114 127 ▶ if (SvOK(rev)) {
Branch: 1 branch
BranchTrueFalseTotal
if (SvOK(rev)) { 127 0 127
1115 127 ▶ if (SvTRUE(rev)) {
Branch: 1 branch
BranchTrueFalseTotal
if (SvTRUE(rev)) { 0 127 127
1116 0 up = SvI64(aTHX_ other);
1117 0 down = SvI64x(self);
1118 }
1119 else {
1120 127 up = SvI64x(self);
1121 127 down = SvI64(aTHX_ other);
1122 }
1123 127 ▶ if (!down)
Branch: 1 branch
BranchTrueFalseTotal
if (!down) 0 127 127
1124 0 croak_string(aTHX_ div_by_0_error);
1125 127 RETVAL = newSVi64(aTHX_ up/down);
1126 }
1127 else {
1128 0 down = SvI64(aTHX_ other);
1129 0 ▶ if (!down)
Branch: 1 branch
BranchTrueFalseTotal
if (!down) 0 0 0
1130 0 croak_string(aTHX_ div_by_0_error);
1131 0 RETVAL = self;
1132 0 SvREFCNT_inc(RETVAL);
1133 0 SvI64x(self) /= down;
1134 }
1135 OUTPUT:
1136 RETVAL
1137  
1138 SV *
1139 mi64_rest(self, other, rev = &PL_sv_no)
1140 SV *self
1141 SV *other
1142 SV *rev
1143 PREINIT:
1144 int64_t up;
1145 int64_t down;
1146 CODE:
1147 3 ▶ if (SvOK(rev)) {
Branch: 1 branch
BranchTrueFalseTotal
if (SvOK(rev)) { 2 1 3
1148 2 ▶ if (SvTRUE(rev)) {
Branch: 1 branch
BranchTrueFalseTotal
if (SvTRUE(rev)) { 0 2 2
1149 0 up = SvI64(aTHX_ other);
1150 0 down = SvI64x(self);
1151 }
1152 else {
1153 2 up = SvI64x(self);
1154 2 down = SvI64(aTHX_ other);
1155 }
1156 2 ▶ if (!down)
Branch: 1 branch
BranchTrueFalseTotal
if (!down) 0 2 2
1157 0 croak_string(aTHX_ div_by_0_error);
1158 2 RETVAL = newSVi64(aTHX_ up % down);
1159 }
1160 else {
1161 1 down = SvI64(aTHX_ other);
1162 1 ▶ if (!down)
Branch: 1 branch
BranchTrueFalseTotal
if (!down) 0 1 1
1163 0 croak_string(aTHX_ div_by_0_error);
1164 1 RETVAL = self;
1165 1 SvREFCNT_inc(RETVAL);
1166 1 SvI64x(self) %= down;
1167 }
1168 OUTPUT:
1169 RETVAL
1170  
1171 SV *
1172 mi64_left(self, other, rev = &PL_sv_no)
1173 SV *self
1174 SV *other
1175 SV *rev
1176 PREINIT:
1177 int64_t a, r;
1178 uint64_t b;
1179 CODE:
1180 235 ▶ if (SvTRUE(rev)) {
Branch: 1 branch
BranchTrueFalseTotal
if (SvTRUE(rev)) { 0 235 235
1181 0 a = SvI64(aTHX_ other);
1182 0 b = SvU64x(self);
1183 }
1184 else {
1185 235 a = SvI64x(self);
1186 235 b = SvU64(aTHX_ other);
1187 }
1188 235 ▶ r = (b > 63 ? 0 : a << b);
Branch: 1 branch
BranchTrueFalseTotal
r = (b > 63 ? 0 : a << b); 229 6 235
1189 235 ▶ if (SvOK(rev))
Branch: 1 branch
BranchTrueFalseTotal
if (SvOK(rev)) 170 65 235
1190 170 RETVAL = newSVi64(aTHX_ r);
1191 else {
1192 65 RETVAL = SvREFCNT_inc(self);
1193 65 SvI64x(self) = r;
1194 }
1195 OUTPUT:
1196 RETVAL
1197  
1198 SV *mi64_right(self, other, rev = &PL_sv_no)
1199 SV *self
1200 SV *other
1201 SV *rev
1202 PREINIT:
1203 int64_t a, r;
1204 uint64_t b;
1205 CODE:
1206 134 ▶ if (SvTRUE(rev)) {
Branch: 1 branch
BranchTrueFalseTotal
if (SvTRUE(rev)) { 0 134 134
1207 0 a = SvI64(aTHX_ other);
1208 0 b = SvU64x(self);
1209 }
1210 else {
1211 134 a = SvI64x(self);
1212 134 b = SvU64(aTHX_ other);
1213 }
1214 134 ▶ r = (b > 63 ? (a < 0 ? -1 : 0) : a >> b);
Branch: 2 branches
BranchTrueFalseTotal
r = (b > 63 ? (a < 0 ? -1 : 0) : a >> b); 8 126 134
r = (b > 63 ? (a < 0 ? -1 : 0) : a >> b); 4 4 8
1215 134 ▶ if (SvOK(rev))
Branch: 1 branch
BranchTrueFalseTotal
if (SvOK(rev)) 68 66 134
1216 68 RETVAL = newSVi64(aTHX_ r);
1217 else {
1218 66 RETVAL = SvREFCNT_inc(self);
1219 66 SvI64x(self) = r;
1220 }
1221 OUTPUT:
1222 RETVAL
1223  
1224 SV *
1225 mi64_pow(self, other, rev = &PL_sv_no)
1226 SV *self
1227 SV *other
1228 SV *rev
1229 PREINIT:
1230 int sign;
1231 uint64_t r;
1232 int64_t a, b;
1233 CODE:
1234 264 ▶ if (SvTRUE(rev)) {
Branch: 1 branch
BranchTrueFalseTotal
if (SvTRUE(rev)) { 0 264 264
1235 0 a = SvI64(aTHX_ other);
1236 0 b = SvI64x(self);
1237 }
1238 else {
1239 264 a = SvI64x(self);
1240 264 b = SvI64(aTHX_ other);
1241 }
1242 264 ▶ if (a < 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (a < 0) { 18 246 264
1243 18 ▶ sign = ((b & 1) ? -1 : 1);
Branch: 1 branch
BranchTrueFalseTotal
sign = ((b & 1) ? -1 : 1); 9 9 18
1244 18 a = -a;
1245 }
1246 246 else sign = 1;
1247 264 ▶ if (b < 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (b < 0) { 10 254 264
1248 10 ▶ if (a == 0) croak_string(aTHX_ div_by_0_error);
Branch: 1 branch
BranchTrueFalseTotal
if (a == 0) croak_string(aTHX_ div_by_0_error); 1 9 10
1249 9 ▶ else if (a == 1) r = sign;
Branch: 1 branch
BranchTrueFalseTotal
else if (a == 1) r = sign; 4 5 9
1250 5 else r = 0;
1251 }
1252 else {
1253 254 uint64_t u = powU64(aTHX_ a, b);
1254 254 ▶ if (may_die_on_overflow && (u > ((sign < 0) ? (~(uint64_t)INT64_MIN + 1) : INT64_MAX))) overflow(aTHX_ pow_error);
Branch: 3 branches
BranchTrueFalseTotal
if (may_die_on_overflow && (u > ((sign < 0) ? (~(uint64_t)INT64_MIN + 1) : INT64_MAX))) overflow(aTHX_ pow_error); 1 253 254
if (may_die_on_overflow && (u > ((sign < 0) ? (~(uint64_t)INT64_MIN + 1) : INT64_MAX))) overflow(aTHX_ pow_error); 0 1 1
if (may_die_on_overflow && (u > ((sign < 0) ? (~(uint64_t)INT64_MIN + 1) : INT64_MAX))) overflow(aTHX_ pow_error); 1 0 1
1255 253 ▶ r = ((sign > 0) ? u : -u);
Branch: 1 branch
BranchTrueFalseTotal
r = ((sign > 0) ? u : -u); 6 247 253
1256 }
1257 262 ▶ if (SvOK(rev))
Branch: 1 branch
BranchTrueFalseTotal
if (SvOK(rev)) 262 0 262
1258 262 RETVAL = newSVi64(aTHX_ r);
1259 else {
1260 0 RETVAL = self;
1261 0 SvREFCNT_inc(RETVAL);
1262 0 SvI64x(self) = r;
1263 }
1264 OUTPUT:
1265 RETVAL
1266  
1267 int
1268 mi64_spaceship(self, other, rev = &PL_sv_no)
1269 SV *self
1270 SV *other
1271 SV *rev
1272 PREINIT:
1273 int64_t left;
1274 int64_t right;
1275 CODE:
1276 4 ▶ if (SvTRUE(rev)) {
Branch: 1 branch
BranchTrueFalseTotal
if (SvTRUE(rev)) { 0 4 4
1277 0 left = SvI64(aTHX_ other);
1278 0 right = SvI64x(self);
1279 }
1280 else {
1281 4 left = SvI64x(self);
1282 4 right = SvI64(aTHX_ other);
1283 }
1284 4 ▶ RETVAL = (left < right ? -1 : left > right ? 1 : 0);
Branch: 2 branches
BranchTrueFalseTotal
RETVAL = (left < right ? -1 : left > right ? 1 : 0); 3 1 4
RETVAL = (left < right ? -1 : left > right ? 1 : 0); 0 4 4
1285 OUTPUT:
1286 RETVAL
1287  
1288 SV *
1289 mi64_eqn(self, other, rev = NULL)
1290 SV *self
1291 SV *other
1292 SV *rev = NO_INIT
1293 CODE:
1294 672 RETVAL = ( SvI64x(self) == SvI64(aTHX_ other)
1295 ? &PL_sv_yes
1296 336 ▶ : &PL_sv_no );
Branch: 1 branch
BranchTrueFalseTotal
: &PL_sv_no ); 336 0 336
1297 OUTPUT:
1298 RETVAL
1299  
1300 SV *
1301 mi64_nen(self, other, rev = NULL)
1302 SV *self
1303 SV *other
1304 SV *rev = NO_INIT
1305 CODE:
1306 2 RETVAL = ( SvI64x(self) != SvI64(aTHX_ other)
1307 ? &PL_sv_yes
1308 1 ▶ : &PL_sv_no );
Branch: 1 branch
BranchTrueFalseTotal
: &PL_sv_no ); 1 0 1
1309 OUTPUT:
1310 RETVAL
1311  
1312 SV *
1313 mi64_gtn(self, other, rev = &PL_sv_no)
1314 SV *self
1315 SV *other
1316 SV *rev
1317 CODE:
1318 2 ▶ if (SvTRUE(rev))
Branch: 1 branch
BranchTrueFalseTotal
if (SvTRUE(rev)) 0 2 2
1319 0 ▶ RETVAL = SvI64x(self) < SvI64(aTHX_ other) ? &PL_sv_yes : &PL_sv_no;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = SvI64x(self) < SvI64(aTHX_ other) ? &PL_sv_yes : &PL_sv_no; 0 0 0
1320 else
1321 2 ▶ RETVAL = SvI64x(self) > SvI64(aTHX_ other) ? &PL_sv_yes : &PL_sv_no;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = SvI64x(self) > SvI64(aTHX_ other) ? &PL_sv_yes : &PL_sv_no; 1 1 2
1322 OUTPUT:
1323 RETVAL
1324  
1325 SV *
1326 mi64_ltn(self, other, rev = &PL_sv_no)
1327 SV *self
1328 SV *other
1329 SV *rev
1330 CODE:
1331 2 ▶ if (SvTRUE(rev))
Branch: 1 branch
BranchTrueFalseTotal
if (SvTRUE(rev)) 0 2 2
1332 0 ▶ RETVAL = SvI64x(self) > SvI64(aTHX_ other) ? &PL_sv_yes : &PL_sv_no;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = SvI64x(self) > SvI64(aTHX_ other) ? &PL_sv_yes : &PL_sv_no; 0 0 0
1333 else
1334 2 ▶ RETVAL = SvI64x(self) < SvI64(aTHX_ other) ? &PL_sv_yes : &PL_sv_no;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = SvI64x(self) < SvI64(aTHX_ other) ? &PL_sv_yes : &PL_sv_no; 1 1 2
1335 OUTPUT:
1336 RETVAL
1337  
1338 SV *
1339 mi64_gen(self, other, rev = &PL_sv_no)
1340 SV *self
1341 SV *other
1342 SV *rev
1343 CODE:
1344 3 ▶ if (SvTRUE(rev))
Branch: 1 branch
BranchTrueFalseTotal
if (SvTRUE(rev)) 0 3 3
1345 0 ▶ RETVAL = SvI64x(self) <= SvI64(aTHX_ other) ? &PL_sv_yes : &PL_sv_no;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = SvI64x(self) <= SvI64(aTHX_ other) ? &PL_sv_yes : &PL_sv_no; 0 0 0
1346 else
1347 3 ▶ RETVAL = SvI64x(self) >= SvI64(aTHX_ other) ? &PL_sv_yes : &PL_sv_no;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = SvI64x(self) >= SvI64(aTHX_ other) ? &PL_sv_yes : &PL_sv_no; 2 1 3
1348 OUTPUT:
1349 RETVAL
1350  
1351 SV *
1352 mi64_len(self, other, rev = &PL_sv_no)
1353 SV *self
1354 SV *other
1355 SV *rev
1356 CODE:
1357 3 ▶ if (SvTRUE(rev))
Branch: 1 branch
BranchTrueFalseTotal
if (SvTRUE(rev)) 0 3 3
1358 0 ▶ RETVAL = SvI64x(self) >= SvI64(aTHX_ other) ? &PL_sv_yes : &PL_sv_no;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = SvI64x(self) >= SvI64(aTHX_ other) ? &PL_sv_yes : &PL_sv_no; 0 0 0
1359 else
1360 3 ▶ RETVAL = SvI64x(self) <= SvI64(aTHX_ other) ? &PL_sv_yes : &PL_sv_no;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = SvI64x(self) <= SvI64(aTHX_ other) ? &PL_sv_yes : &PL_sv_no; 2 1 3
1361 OUTPUT:
1362 RETVAL
1363  
1364 SV *
1365 mi64_and(self, other, rev = &PL_sv_no)
1366 SV *self
1367 SV *other
1368 SV *rev
1369 CODE:
1370 5 ▶ if (SvOK(rev))
Branch: 1 branch
BranchTrueFalseTotal
if (SvOK(rev)) 5 0 5
1371 5 RETVAL = newSVi64(aTHX_ SvI64x(self) & SvI64(aTHX_ other));
1372 else {
1373 0 RETVAL = self;
1374 0 SvREFCNT_inc(RETVAL);
1375 0 SvI64x(self) &= SvI64(aTHX_ other);
1376 }
1377 OUTPUT:
1378 RETVAL
1379  
1380 SV *
1381 mi64_or(self, other, rev = &PL_sv_no)
1382 SV *self
1383 SV *other
1384 SV *rev
1385 CODE:
1386 1 ▶ if (SvOK(rev))
Branch: 1 branch
BranchTrueFalseTotal
if (SvOK(rev)) 1 0 1
1387 1 RETVAL = newSVi64(aTHX_ SvI64x(self) | SvI64(aTHX_ other));
1388 else {
1389 0 RETVAL = self;
1390 0 SvREFCNT_inc(RETVAL);
1391 0 SvI64x(self) |= SvI64(aTHX_ other);
1392 }
1393 OUTPUT:
1394 RETVAL
1395  
1396 SV *
1397 mi64_xor(self, other, rev = &PL_sv_no)
1398 SV *self
1399 SV *other
1400 SV *rev
1401 CODE:
1402 0 ▶ if (SvOK(rev))
Branch: 1 branch
BranchTrueFalseTotal
if (SvOK(rev)) 0 0 0
1403 0 RETVAL = newSVi64(aTHX_ SvI64x(self) ^ SvI64(aTHX_ other));
1404 else {
1405 0 RETVAL = self;
1406 0 SvREFCNT_inc(RETVAL);
1407 0 SvI64x(self) ^= SvI64(aTHX_ other);
1408 }
1409 OUTPUT:
1410 RETVAL
1411  
1412 SV *
1413 mi64_not(self, other = NULL, rev = NULL)
1414 SV *self
1415 SV *other = NO_INIT
1416 SV *rev = NO_INIT
1417 CODE:
1418 0 ▶ RETVAL = SvI64x(self) ? &PL_sv_no : &PL_sv_yes;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = SvI64x(self) ? &PL_sv_no : &PL_sv_yes; 0 0 0
1419 OUTPUT:
1420 RETVAL
1421  
1422 SV *
1423 mi64_bnot(self, other = NULL, rev = NULL)
1424 SV *self
1425 SV *other = NO_INIT
1426 SV *rev = NO_INIT
1427 CODE:
1428 0 RETVAL = newSVi64(aTHX_ ~SvI64x(self));
1429 OUTPUT:
1430 RETVAL
1431  
1432 SV *
1433 mi64_neg(self, other = NULL, rev = NULL)
1434 SV *self
1435 SV *other = NO_INIT
1436 SV *rev = NO_INIT
1437 CODE:
1438 2 RETVAL = newSVi64(aTHX_ -SvI64x(self));
1439 OUTPUT:
1440 RETVAL
1441  
1442 SV *
1443 mi64_bool(self, other = NULL, rev = NULL)
1444 SV *self
1445 SV *other = NO_INIT
1446 SV *rev = NO_INIT
1447 CODE:
1448 0 ▶ RETVAL = SvI64x(self) ? &PL_sv_yes : &PL_sv_no;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = SvI64x(self) ? &PL_sv_yes : &PL_sv_no; 0 0 0
1449 OUTPUT:
1450 RETVAL
1451  
1452 SV *
1453 mi64_number(self, other = NULL, rev = NULL)
1454 SV *self
1455 SV *other = NO_INIT
1456 SV *rev = NO_INIT
1457 CODE:
1458 1 RETVAL = si64_to_number(aTHX_ self);
1459 OUTPUT:
1460 RETVAL
1461  
1462 SV *
1463 mi64_clone(self, other = NULL, rev = NULL)
1464 SV *self
1465 SV *other = NO_INIT
1466 SV *rev = NO_INIT
1467 CODE:
1468 5 RETVAL = newSVi64(aTHX_ SvI64x(self));
1469 OUTPUT:
1470 RETVAL
1471  
1472 SV *
1473 mi64_string(self, other = NULL, rev = NULL)
1474 SV *self
1475 SV *other = NO_INIT
1476 SV *rev = NO_INIT
1477 CODE:
1478 1776 RETVAL = i64_to_string(aTHX_ SvI64x(self), 10);
1479 OUTPUT:
1480 RETVAL
1481  
1482 void
1483 mi64STORABLE_thaw(self, cloning, serialized, ...)
1484 SV *self
1485 SV *cloning = NO_INIT
1486 SV *serialized
1487 CODE:
1488 100 ▶ if (SvROK(self) && sv_isa(self, "Math::Int64")) {
Branch: 2 branches
BranchTrueFalseTotal
if (SvROK(self) && sv_isa(self, "Math::Int64")) { 100 0 100
if (SvROK(self) && sv_isa(self, "Math::Int64")) { 100 0 100
1489 100 SV *target = SvRV(self);
1490 100 SV *tmp = sv_2mortal(newSVu64(aTHX_ BER_to_int64(aTHX_ serialized)));
1491 100 sv_setsv(target, SvRV(tmp));
1492 100 SvREADONLY_on(target);
1493 }
1494 else
1495 0 croak_string(aTHX_ "Bad object for Math::Int64::STORABLE_thaw call");
1496  
1497 SV *
1498 mi64STORABLE_freeze(self, cloning = NULL)
1499 SV *self
1500 SV *cloning = NO_INIT
1501 CODE:
1502 100 RETVAL = int64_to_BER(aTHX_ SvI64x(self));
1503 OUTPUT:
1504 RETVAL
1505  
1506 MODULE = Math::Int64 PACKAGE = Math::UInt64 PREFIX=mu64
1507 PROTOTYPES: DISABLE
1508  
1509 SV *
1510 mu64_inc(self, other = NULL, rev = NULL)
1511 SV *self
1512 SV *other = NO_INIT
1513 SV *rev = NO_INIT
1514 CODE:
1515 2 ▶ if (may_die_on_overflow && (SvU64x(self) == UINT64_MAX)) overflow(aTHX_ inc_error);
Branch: 2 branches
BranchTrueFalseTotal
if (may_die_on_overflow && (SvU64x(self) == UINT64_MAX)) overflow(aTHX_ inc_error); 2 0 2
if (may_die_on_overflow && (SvU64x(self) == UINT64_MAX)) overflow(aTHX_ inc_error); 2 0 2
1516 1 SvU64x(self)++;
1517 1 RETVAL = SvREFCNT_inc(self);
1518 OUTPUT:
1519 RETVAL
1520  
1521 SV *
1522 mu64_dec(self, other = NULL, rev = NULL)
1523 SV *self
1524 SV *other = NO_INIT
1525 SV *rev = NO_INIT
1526 CODE:
1527 2 ▶ if (may_die_on_overflow && (SvU64x(self) == 0)) overflow(aTHX_ dec_error);
Branch: 2 branches
BranchTrueFalseTotal
if (may_die_on_overflow && (SvU64x(self) == 0)) overflow(aTHX_ dec_error); 2 0 2
if (may_die_on_overflow && (SvU64x(self) == 0)) overflow(aTHX_ dec_error); 2 0 2
1528 1 SvU64x(self)--;
1529 1 RETVAL = SvREFCNT_inc(self);
1530 OUTPUT:
1531 RETVAL
1532  
1533 SV *
1534 mu64_add(self, other, rev = &PL_sv_no)
1535 SV *self
1536 SV *other
1537 SV *rev
1538 PREINIT:
1539 uint64_t a, b;
1540 CODE:
1541 74 a = SvU64x(self);
1542 74 b = SvU64(aTHX_ other);
1543 74 ▶ if (may_die_on_overflow && (UINT64_MAX - a < b)) overflow(aTHX_ add_error);
Branch: 2 branches
BranchTrueFalseTotal
if (may_die_on_overflow && (UINT64_MAX - a < b)) overflow(aTHX_ add_error); 2 72 74
if (may_die_on_overflow && (UINT64_MAX - a < b)) overflow(aTHX_ add_error); 2 0 2
1544 73 ▶ if (SvOK(rev))
Branch: 1 branch
BranchTrueFalseTotal
if (SvOK(rev)) 72 1 73
1545 72 RETVAL = newSVu64(aTHX_ a + b);
1546 else {
1547 1 RETVAL = self;
1548 1 SvREFCNT_inc(RETVAL);
1549 1 SvU64x(self) = a + b;
1550 }
1551 OUTPUT:
1552 RETVAL
1553  
1554 SV *
1555 mu64_sub(self, other, rev = &PL_sv_no)
1556 SV *self
1557 SV *other
1558 SV *rev
1559 PREINIT:
1560 uint64_t a, b;
1561 CODE:
1562 73 ▶ if (SvTRUE(rev)) {
Branch: 1 branch
BranchTrueFalseTotal
if (SvTRUE(rev)) { 0 73 73
1563 0 a = SvU64(aTHX_ other);
1564 0 b = SvU64x(self);
1565 }
1566 else {
1567 73 a = SvU64x(self);
1568 73 b = SvU64(aTHX_ other);
1569 }
1570 73 ▶ if (may_die_on_overflow && (b > a)) overflow(aTHX_ sub_error);
Branch: 2 branches
BranchTrueFalseTotal
if (may_die_on_overflow && (b > a)) overflow(aTHX_ sub_error); 3 70 73
if (may_die_on_overflow && (b > a)) overflow(aTHX_ sub_error); 2 1 3
1571 72 ▶ if (SvOK(rev))
Branch: 1 branch
BranchTrueFalseTotal
if (SvOK(rev)) 71 1 72
1572 71 RETVAL = newSVu64(aTHX_ a - b);
1573 else {
1574 1 RETVAL = SvREFCNT_inc(self);
1575 1 SvU64x(self) = a - b;
1576 }
1577 OUTPUT:
1578 RETVAL
1579  
1580 SV *
1581 mu64_mul(self, other, rev = &PL_sv_no)
1582 SV *self
1583 SV *other
1584 SV *rev
1585 PREINIT:
1586 uint64_t a, b;
1587 CODE:
1588 83 a = SvU64x(self);
1589 83 b = SvU64(aTHX_ other);
1590 83 ▶ if (may_die_on_overflow) mul_check_overflow(aTHX_ a, b, mul_error);
Branch: 1 branch
BranchTrueFalseTotal
if (may_die_on_overflow) mul_check_overflow(aTHX_ a, b, mul_error); 6 77 83
1591 81 ▶ if (SvOK(rev))
Branch: 1 branch
BranchTrueFalseTotal
if (SvOK(rev)) 80 1 81
1592 80 RETVAL = newSVu64(aTHX_ a * b);
1593 else {
1594 1 RETVAL = SvREFCNT_inc(self);
1595 1 SvU64x(self) = a * b;
1596 }
1597 OUTPUT:
1598 RETVAL
1599  
1600 SV *
1601 mu64_div(self, other, rev = &PL_sv_no)
1602 SV *self
1603 SV *other
1604 SV *rev
1605 PREINIT:
1606 uint64_t up, down;
1607 CODE:
1608 129 ▶ if (SvOK(rev)) {
Branch: 1 branch
BranchTrueFalseTotal
if (SvOK(rev)) { 129 0 129
1609 129 ▶ if (SvTRUE(rev)) {
Branch: 1 branch
BranchTrueFalseTotal
if (SvTRUE(rev)) { 0 129 129
1610 0 up = SvU64(aTHX_ other);
1611 0 down = SvU64x(self);
1612 }
1613 else {
1614 129 up = SvU64x(self);
1615 129 down = SvU64(aTHX_ other);
1616 }
1617 129 ▶ if (!down)
Branch: 1 branch
BranchTrueFalseTotal
if (!down) 0 129 129
1618 0 croak_string(aTHX_ div_by_0_error);
1619 129 RETVAL = newSVu64(aTHX_ up/down);
1620 }
1621 else {
1622 0 down = SvU64(aTHX_ other);
1623 0 ▶ if (!down)
Branch: 1 branch
BranchTrueFalseTotal
if (!down) 0 0 0
1624 0 croak_string(aTHX_ div_by_0_error);
1625 0 RETVAL = self;
1626 0 SvREFCNT_inc(RETVAL);
1627 0 SvU64x(self) /= down;
1628 }
1629 OUTPUT:
1630 RETVAL
1631  
1632 SV *
1633 mu64_rest(self, other, rev = &PL_sv_no)
1634 SV *self
1635 SV *other
1636 SV *rev
1637 PREINIT:
1638 uint64_t up;
1639 uint64_t down;
1640 CODE:
1641 3 ▶ if (SvOK(rev)) {
Branch: 1 branch
BranchTrueFalseTotal
if (SvOK(rev)) { 2 1 3
1642 2 ▶ if (SvTRUE(rev)) {
Branch: 1 branch
BranchTrueFalseTotal
if (SvTRUE(rev)) { 0 2 2
1643 0 up = SvU64(aTHX_ other);
1644 0 down = SvU64x(self);
1645 }
1646 else {
1647 2 up = SvU64x(self);
1648 2 down = SvU64(aTHX_ other);
1649 }
1650 2 ▶ if (!down)
Branch: 1 branch
BranchTrueFalseTotal
if (!down) 0 2 2
1651 0 croak_string(aTHX_ div_by_0_error);
1652 2 RETVAL = newSVu64(aTHX_ up % down);
1653 }
1654 else {
1655 1 down = SvU64(aTHX_ other);
1656 1 ▶ if (!down)
Branch: 1 branch
BranchTrueFalseTotal
if (!down) 0 1 1
1657 0 croak_string(aTHX_ div_by_0_error);
1658 1 RETVAL = self;
1659 1 SvREFCNT_inc(RETVAL);
1660 1 SvU64x(self) %= down;
1661 }
1662 OUTPUT:
1663 RETVAL
1664  
1665 SV *mu64_left(self, other, rev = &PL_sv_no)
1666 SV *self
1667 SV *other
1668 SV *rev
1669 PREINIT:
1670 uint64_t a, b, r;
1671 CODE:
1672 236 ▶ if (SvTRUE(rev)) {
Branch: 1 branch
BranchTrueFalseTotal
if (SvTRUE(rev)) { 0 236 236
1673 0 a = SvU64(aTHX_ other);
1674 0 b = SvU64x(self);
1675 }
1676 else {
1677 236 a = SvU64x(self);
1678 236 b = SvU64(aTHX_ other);
1679 }
1680 236 ▶ r = (b > 63 ? 0 : a << b);
Branch: 1 branch
BranchTrueFalseTotal
r = (b > 63 ? 0 : a << b); 234 2 236
1681 236 ▶ if (SvOK(rev))
Branch: 1 branch
BranchTrueFalseTotal
if (SvOK(rev)) 172 64 236
1682 172 RETVAL = newSVu64(aTHX_ r);
1683 else {
1684 64 RETVAL = SvREFCNT_inc(self);
1685 64 SvU64x(self) = r;
1686 }
1687 OUTPUT:
1688 RETVAL
1689  
1690 SV *mu64_right(self, other, rev = &PL_sv_no)
1691 SV *self
1692 SV *other
1693 SV *rev
1694 PREINIT:
1695 uint64_t a, b, r;
1696 CODE:
1697 127 ▶ if (SvTRUE(rev)) {
Branch: 1 branch
BranchTrueFalseTotal
if (SvTRUE(rev)) { 0 127 127
1698 0 a = SvU64(aTHX_ other);
1699 0 b = SvU64x(self);
1700 }
1701 else {
1702 127 a = SvU64x(self);
1703 127 b = SvU64(aTHX_ other);
1704 }
1705 127 ▶ r = (b > 63 ? 0 : a >> b);
Branch: 1 branch
BranchTrueFalseTotal
r = (b > 63 ? 0 : a >> b); 127 0 127
1706 127 ▶ if (SvOK(rev))
Branch: 1 branch
BranchTrueFalseTotal
if (SvOK(rev)) 64 63 127
1707 64 RETVAL = newSVu64(aTHX_ r);
1708 else {
1709 63 RETVAL = SvREFCNT_inc(self);
1710 63 SvU64x(self) = r;
1711 }
1712 OUTPUT:
1713 RETVAL
1714  
1715 SV *
1716 mu64_pow(self, other, rev = &PL_sv_no)
1717 SV *self
1718 SV *other
1719 SV *rev
1720 PREINIT:
1721 uint64_t r;
1722 int64_t a, b;
1723 CODE:
1724 304 ▶ if (SvTRUE(rev)) {
Branch: 1 branch
BranchTrueFalseTotal
if (SvTRUE(rev)) { 0 304 304
1725 0 a = SvU64(aTHX_ other);
1726 0 b = SvU64x(self);
1727 }
1728 else {
1729 304 a = SvU64x(self);
1730 304 b = SvU64(aTHX_ other);
1731 }
1732 304 r = powU64(aTHX_ a, b);
1733 302 ▶ if (SvOK(rev))
Branch: 1 branch
BranchTrueFalseTotal
if (SvOK(rev)) 302 0 302
1734 302 RETVAL = newSVu64(aTHX_ r);
1735 else {
1736 0 RETVAL = self;
1737 0 SvREFCNT_inc(RETVAL);
1738 0 SvU64x(self) = r;
1739 }
1740 OUTPUT:
1741 RETVAL
1742  
1743 int
1744 mu64_spaceship(self, other, rev = &PL_sv_no)
1745 SV *self
1746 SV *other
1747 SV *rev
1748 PREINIT:
1749 uint64_t left;
1750 uint64_t right;
1751 CODE:
1752 4 ▶ if (SvTRUE(rev)) {
Branch: 1 branch
BranchTrueFalseTotal
if (SvTRUE(rev)) { 0 4 4
1753 0 left = SvU64(aTHX_ other);
1754 0 right = SvU64x(self);
1755 }
1756 else {
1757 4 left = SvU64x(self);
1758 4 right = SvU64(aTHX_ other);
1759 }
1760 4 ▶ RETVAL = (left < right ? -1 : left > right ? 1 : 0);
Branch: 2 branches
BranchTrueFalseTotal
RETVAL = (left < right ? -1 : left > right ? 1 : 0); 3 1 4
RETVAL = (left < right ? -1 : left > right ? 1 : 0); 0 4 4
1761 OUTPUT:
1762 RETVAL
1763  
1764 SV *
1765 mu64_eqn(self, other, rev = NULL)
1766 SV *self
1767 SV *other
1768 SV *rev = NO_INIT
1769 CODE:
1770 592 RETVAL = ( SvU64x(self) == SvU64(aTHX_ other)
1771 ? &PL_sv_yes
1772 296 ▶ : &PL_sv_no );
Branch: 1 branch
BranchTrueFalseTotal
: &PL_sv_no ); 296 0 296
1773 OUTPUT:
1774 RETVAL
1775  
1776 SV *
1777 mu64_nen(self, other, rev = NULL)
1778 SV *self
1779 SV *other
1780 SV *rev = NO_INIT
1781 CODE:
1782 0 RETVAL = ( SvU64x(self) != SvU64(aTHX_ other)
1783 ? &PL_sv_yes
1784 0 ▶ : &PL_sv_no );
Branch: 1 branch
BranchTrueFalseTotal
: &PL_sv_no ); 0 0 0
1785 OUTPUT:
1786 RETVAL
1787  
1788 SV *
1789 mu64_gtn(self, other, rev = &PL_sv_no)
1790 SV *self
1791 SV *other
1792 SV *rev
1793 CODE:
1794 2 ▶ if (SvTRUE(rev))
Branch: 1 branch
BranchTrueFalseTotal
if (SvTRUE(rev)) 0 2 2
1795 0 ▶ RETVAL = SvU64x(self) < SvU64(aTHX_ other) ? &PL_sv_yes : &PL_sv_no;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = SvU64x(self) < SvU64(aTHX_ other) ? &PL_sv_yes : &PL_sv_no; 0 0 0
1796 else
1797 2 ▶ RETVAL = SvU64x(self) > SvU64(aTHX_ other) ? &PL_sv_yes : &PL_sv_no;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = SvU64x(self) > SvU64(aTHX_ other) ? &PL_sv_yes : &PL_sv_no; 1 1 2
1798 OUTPUT:
1799 RETVAL
1800  
1801 SV *
1802 mu64_ltn(self, other, rev = &PL_sv_no)
1803 SV *self
1804 SV *other
1805 SV *rev
1806 CODE:
1807 2 ▶ if (SvTRUE(rev))
Branch: 1 branch
BranchTrueFalseTotal
if (SvTRUE(rev)) 0 2 2
1808 0 ▶ RETVAL = SvU64x(self) > SvU64(aTHX_ other) ? &PL_sv_yes : &PL_sv_no;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = SvU64x(self) > SvU64(aTHX_ other) ? &PL_sv_yes : &PL_sv_no; 0 0 0
1809 else
1810 2 ▶ RETVAL = SvU64x(self) < SvU64(aTHX_ other) ? &PL_sv_yes : &PL_sv_no;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = SvU64x(self) < SvU64(aTHX_ other) ? &PL_sv_yes : &PL_sv_no; 1 1 2
1811 OUTPUT:
1812 RETVAL
1813  
1814 SV *
1815 mu64_gen(self, other, rev = &PL_sv_no)
1816 SV *self
1817 SV *other
1818 SV *rev
1819 CODE:
1820 3 ▶ if (SvTRUE(rev))
Branch: 1 branch
BranchTrueFalseTotal
if (SvTRUE(rev)) 0 3 3
1821 0 ▶ RETVAL = SvU64x(self) <= SvU64(aTHX_ other) ? &PL_sv_yes : &PL_sv_no;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = SvU64x(self) <= SvU64(aTHX_ other) ? &PL_sv_yes : &PL_sv_no; 0 0 0
1822 else
1823 3 ▶ RETVAL = SvU64x(self) >= SvU64(aTHX_ other) ? &PL_sv_yes : &PL_sv_no;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = SvU64x(self) >= SvU64(aTHX_ other) ? &PL_sv_yes : &PL_sv_no; 2 1 3
1824 OUTPUT:
1825 RETVAL
1826  
1827 SV *
1828 mu64_len(self, other, rev = &PL_sv_no)
1829 SV *self
1830 SV *other
1831 SV *rev
1832 CODE:
1833 3 ▶ if (SvTRUE(rev))
Branch: 1 branch
BranchTrueFalseTotal
if (SvTRUE(rev)) 0 3 3
1834 0 ▶ RETVAL = SvU64x(self) >= SvU64(aTHX_ other) ? &PL_sv_yes : &PL_sv_no;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = SvU64x(self) >= SvU64(aTHX_ other) ? &PL_sv_yes : &PL_sv_no; 0 0 0
1835 else
1836 3 ▶ RETVAL = SvU64x(self) <= SvU64(aTHX_ other) ? &PL_sv_yes : &PL_sv_no;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = SvU64x(self) <= SvU64(aTHX_ other) ? &PL_sv_yes : &PL_sv_no; 2 1 3
1837 OUTPUT:
1838 RETVAL
1839  
1840 SV *
1841 mu64_and(self, other, rev = &PL_sv_no)
1842 SV *self
1843 SV *other
1844 SV *rev
1845 CODE:
1846 2 ▶ if (SvOK(rev))
Branch: 1 branch
BranchTrueFalseTotal
if (SvOK(rev)) 2 0 2
1847 2 RETVAL = newSVu64(aTHX_ SvU64x(self) & SvU64(aTHX_ other));
1848 else {
1849 0 RETVAL = self;
1850 0 SvREFCNT_inc(RETVAL);
1851 0 SvU64x(self) &= SvU64(aTHX_ other);
1852 }
1853 OUTPUT:
1854 RETVAL
1855  
1856 SV *
1857 mu64_or(self, other, rev = &PL_sv_no)
1858 SV *self
1859 SV *other
1860 SV *rev
1861 CODE:
1862 0 ▶ if (SvOK(rev))
Branch: 1 branch
BranchTrueFalseTotal
if (SvOK(rev)) 0 0 0
1863 0 RETVAL = newSVu64(aTHX_ SvU64x(self) | SvU64(aTHX_ other));
1864 else {
1865 0 RETVAL = self;
1866 0 SvREFCNT_inc(RETVAL);
1867 0 SvU64x(self) |= SvU64(aTHX_ other);
1868 }
1869 OUTPUT:
1870 RETVAL
1871  
1872 SV *
1873 mu64_xor(self, other, rev = &PL_sv_no)
1874 SV *self
1875 SV *other
1876 SV *rev
1877 CODE:
1878 0 ▶ if (SvOK(rev))
Branch: 1 branch
BranchTrueFalseTotal
if (SvOK(rev)) 0 0 0
1879 0 RETVAL = newSVu64(aTHX_ SvU64x(self) ^ SvU64(aTHX_ other));
1880 else {
1881 0 RETVAL = self;
1882 0 SvREFCNT_inc(RETVAL);
1883 0 SvU64x(self) ^= SvU64(aTHX_ other);
1884 }
1885 OUTPUT:
1886 RETVAL
1887  
1888 SV *
1889 mu64_not(self, other = NULL, rev = NULL)
1890 SV *self
1891 SV *other = NO_INIT
1892 SV *rev = NO_INIT
1893 CODE:
1894 0 ▶ RETVAL = SvU64x(self) ? &PL_sv_no : &PL_sv_yes;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = SvU64x(self) ? &PL_sv_no : &PL_sv_yes; 0 0 0
1895 OUTPUT:
1896 RETVAL
1897  
1898 SV *
1899 mu64_bnot(self, other = NULL, rev = NULL)
1900 SV *self
1901 SV *other = NO_INIT
1902 SV *rev = NO_INIT
1903 CODE:
1904 0 RETVAL = newSVu64(aTHX_ ~SvU64x(self));
1905 OUTPUT:
1906 RETVAL
1907  
1908 SV *
1909 mu64_neg(self, other = NULL, rev = NULL)
1910 SV *self
1911 SV *other = NO_INIT
1912 SV *rev = NO_INIT
1913 CODE:
1914 0 RETVAL = newSVu64(aTHX_ ~(SvU64x(self)-1));
1915 OUTPUT:
1916 RETVAL
1917  
1918 SV *
1919 mu64_bool(self, other = NULL, rev = NULL)
1920 SV *self
1921 SV *other = NO_INIT
1922 SV *rev = NO_INIT
1923 CODE:
1924 0 ▶ RETVAL = SvU64x(self) ? &PL_sv_yes : &PL_sv_no;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = SvU64x(self) ? &PL_sv_yes : &PL_sv_no; 0 0 0
1925 OUTPUT:
1926 RETVAL
1927  
1928 SV *
1929 mu64_number(self, other = NULL, rev = NULL)
1930 SV *self
1931 SV *other = NO_INIT
1932 SV *rev = NO_INIT
1933 CODE:
1934 1 RETVAL = su64_to_number(aTHX_ self);
1935 OUTPUT:
1936 RETVAL
1937  
1938 SV *
1939 mu64_clone(self, other = NULL, rev = NULL)
1940 SV *self
1941 SV *other = NO_INIT
1942 SV *rev = NO_INIT
1943 CODE:
1944 5 RETVAL = newSVu64(aTHX_ SvU64x(self));
1945 OUTPUT:
1946 RETVAL
1947  
1948 SV *
1949 mu64_string(self, other = NULL, rev = NULL)
1950 SV *self
1951 SV *other = NO_INIT
1952 SV *rev = NO_INIT
1953 CODE:
1954 1631 RETVAL = u64_to_string_with_sign(aTHX_ SvU64x(self), 10, 0);
1955 OUTPUT:
1956 RETVAL
1957  
1958 void
1959 mu64STORABLE_thaw(self, cloning, serialized, ...)
1960 SV *self
1961 SV *cloning = NO_INIT
1962 SV *serialized
1963 CODE:
1964 100 ▶ if (SvROK(self) && sv_isa(self, "Math::UInt64")) {
Branch: 2 branches
BranchTrueFalseTotal
if (SvROK(self) && sv_isa(self, "Math::UInt64")) { 100 0 100
if (SvROK(self) && sv_isa(self, "Math::UInt64")) { 100 0 100
1965 100 SV *target = SvRV(self);
1966 100 SV *tmp = sv_2mortal(newSVu64(aTHX_ BER_to_uint64(aTHX_ serialized)));
1967 100 sv_setsv(target, SvRV(tmp));
1968 100 SvREADONLY_on(target);
1969 }
1970 else
1971 0 croak_string(aTHX_ "Bad object for Math::UInt64::STORABLE_thaw call");
1972  
1973 SV *
1974 mu64STORABLE_freeze(self, cloning = NULL)
1975 SV *self
1976 SV *cloning = NO_INIT
1977 CODE:
1978 100 RETVAL = uint64_to_BER(aTHX_ SvU64x(self));
1979 OUTPUT:
1980 RETVAL
1981  
« blib/lib/Math/Int64/native_if_available.pm ↑ Summary isaac64.h »