File Coverage

lib/PDL/Ops-pp-ipow.c
Criterion Covered Total %
statement 31 62 50.0
branch 46 298 15.4
condition n/a
subroutine n/a
pod n/a
total 77 360 21.3


line stmt bran cond sub pod time code
1              
2             #line 453 "lib/PDL/PP.pm"
3             /*
4             * THIS FILE WAS GENERATED BY PDL::PP from lib/PDL/Ops.pd! Do not modify!
5             */
6              
7             #define PDL_FREE_CODE(trans, destroy, comp_free_code, ntpriv_free_code) \
8             if (destroy) { \
9             comp_free_code \
10             } \
11             if ((trans)->dims_redone) { \
12             ntpriv_free_code \
13             }
14              
15             #include "EXTERN.h"
16             #include "perl.h"
17             #include "XSUB.h"
18             #include "pdl.h"
19             #include "pdlcore.h"
20             #define PDL PDL_Ops
21             extern Core* PDL; /* Structure hold core C functions */
22             #line 23 "lib/PDL/Ops-pp-ipow.c"
23              
24             #include
25              
26             #define MOD(X,N) (((N) == 0) ? 0 : ( (X) - (PDL_ABS(N)) * ((long long)((X)/(PDL_ABS(N))) + ( ( ((N) * ((long long)((X)/(N)))) != (X) ) ? ( ( ((N)<0) ? 1 : 0 ) + ( (((X)<0) ? -1 : 0))) : 0 ))))
27             #define BU_MOD(X,N)(((N) == 0) ? 0 : ( (X)-(N)*((uint64_t)((X)/(N))) ))
28             #define SPACE(A,B) ( ((A)<(B)) ? -1 : ((A)!=(B)) )
29              
30             #line 83 "lib/PDL/Ops.pd"
31             #define PDL_BADVAL_WARN_X(datatype, ctype, ppsym, ...) \
32             bad_anyval.type = datatype; bad_anyval.value.ppsym = PDL->bvals.ppsym;
33             #define PDL_BADVAL_WARN(var) \
34             { \
35             PDL_Anyval bad_anyval = { PDL_INVALID, {0} }; \
36             if (!(var->has_badvalue && var->badvalue.type != var->datatype)) { \
37             if (var->has_badvalue) \
38             bad_anyval = var->badvalue; \
39             else { \
40             PDL_GENERICSWITCH(PDL_TYPELIST_ALL, var->datatype, PDL_BADVAL_WARN_X, ) \
41             } \
42             } \
43             if (bad_anyval.type < 0) \
44             barf("Error getting badvalue, type=%d", bad_anyval.type); \
45             complex double bad_c; \
46             ANYVAL_TO_CTYPE(bad_c, complex double, bad_anyval); \
47             if( bad_c == 0 || bad_c == 1 ) \
48             warn(#var " badvalue is set to 0 or 1. This will cause data loss when using badvalues for comparison operators."); \
49             }
50              
51             #line 1857 "lib/PDL/PP.pm"
52             pdl_error pdl_ipow_readdata(pdl_trans *__privtrans) {
53             pdl_error PDL_err = {0, NULL, 0};
54             #line 55 "lib/PDL/Ops-pp-ipow.c"
55 16 50         if (!__privtrans->broadcast.incs) return PDL->make_error(PDL_EUSERERROR, "Error in ipow:" "broadcast.incs NULL");
56             /* broadcastloop declarations */
57             int __brcloopval;
58             register PDL_Indx __tind0,__tind1; /* counters along dim */
59 16           register PDL_Indx __tnpdls = __privtrans->broadcast.npdls;
60             /* dims here are how many steps along those dims */
61 16           register PDL_Indx __tinc0_a = PDL_BRC_INC(__privtrans->broadcast.incs,__tnpdls,0,0);
62 16           register PDL_Indx __tinc0_b = PDL_BRC_INC(__privtrans->broadcast.incs,__tnpdls,1,0);
63 16           register PDL_Indx __tinc0_ans = PDL_BRC_INC(__privtrans->broadcast.incs,__tnpdls,2,0);
64 16           register PDL_Indx __tinc1_a = PDL_BRC_INC(__privtrans->broadcast.incs,__tnpdls,0,1);
65 16           register PDL_Indx __tinc1_b = PDL_BRC_INC(__privtrans->broadcast.incs,__tnpdls,1,1);
66 16           register PDL_Indx __tinc1_ans = PDL_BRC_INC(__privtrans->broadcast.incs,__tnpdls,2,1);
67             #define PDL_BROADCASTLOOP_START_ipow_readdata PDL_BROADCASTLOOP_START( \
68             readdata, \
69             __privtrans->broadcast, \
70             __privtrans->vtable, \
71             a_datap += __offsp[0]; \
72             b_datap += __offsp[1]; \
73             ans_datap += __offsp[2]; \
74             , \
75             ( ,a_datap += __tinc1_a - __tinc0_a * __tdims0 \
76             ,b_datap += __tinc1_b - __tinc0_b * __tdims0 \
77             ,ans_datap += __tinc1_ans - __tinc0_ans * __tdims0 \
78             ), \
79             ( ,a_datap += __tinc0_a \
80             ,b_datap += __tinc0_b \
81             ,ans_datap += __tinc0_ans \
82             ) \
83             )
84             #define PDL_BROADCASTLOOP_END_ipow_readdata PDL_BROADCASTLOOP_END( \
85             __privtrans->broadcast, \
86             a_datap -= __tinc1_a * __tdims1 + __offsp[0]; \
87             b_datap -= __tinc1_b * __tdims1 + __offsp[1]; \
88             ans_datap -= __tinc1_ans * __tdims1 + __offsp[2]; \
89             )
90             #ifndef PDL_DECLARE_PARAMS_ipow_1
91             #define PDL_DECLARE_PARAMS_ipow_1(PDL_TYPE_OP,PDL_PPSYM_OP,PDL_TYPE_PARAM_b,PDL_PPSYM_PARAM_b) \
92             PDL_DECLARE_PARAMETER(PDL_TYPE_OP, a, (__privtrans->pdls[0]), 1, PDL_PPSYM_OP) \
93             PDL_DECLARE_PARAMETER(PDL_TYPE_PARAM_b, b, (__privtrans->pdls[1]), 1, PDL_PPSYM_PARAM_b) \
94             PDL_DECLARE_PARAMETER(PDL_TYPE_OP, ans, (__privtrans->pdls[2]), 1, PDL_PPSYM_OP)
95             #endif
96             #define PDL_IF_BAD(t,f) f
97 16           switch (__privtrans->__datatype) { /* Start generic switch */
98 0           case PDL_ULL: {
99 0 0         PDL_DECLARE_PARAMS_ipow_1(PDL_ULongLong,P,PDL_LongLong,Q)
    0          
    0          
    0          
    0          
    0          
    0          
    0          
    0          
100 0 0         PDL_BROADCASTLOOP_START_ipow_readdata {
    0          
    0          
    0          
    0          
    0          
    0          
101             #line 444 "lib/PDL/Ops.pd"
102              
103             PDL_LongLong n = (b_datap)[0];
104             if (n == 0) {
105             (ans_datap)[0] = 1;
106             continue;
107             }
108             PDL_ULongLong y = 1;
109             PDL_ULongLong x = (a_datap)[0];
110             if (n < 0) {
111             x = 1 / x;
112             n = -n;
113             }
114             while (n > 1) {
115             if (n % 2) {
116             y *= x;
117             n -= 1;
118             }
119             x *= x;
120             n /= 2;
121             }
122             (ans_datap)[0] = x * y;
123             #line 124 "lib/PDL/Ops-pp-ipow.c"
124 0 0         }PDL_BROADCASTLOOP_END_ipow_readdata
    0          
125 0           } break;
126 2           case PDL_LL: {
127 2 50         PDL_DECLARE_PARAMS_ipow_1(PDL_LongLong,Q,PDL_LongLong,Q)
    50          
    50          
    50          
    50          
    50          
    50          
    50          
    50          
128 22 50         PDL_BROADCASTLOOP_START_ipow_readdata {
    50          
    50          
    50          
    50          
    100          
    100          
129             #line 444 "lib/PDL/Ops.pd"
130              
131             PDL_LongLong n = (b_datap)[0];
132             if (n == 0) {
133             (ans_datap)[0] = 1;
134             continue;
135             }
136             PDL_LongLong y = 1;
137             PDL_LongLong x = (a_datap)[0];
138             if (n < 0) {
139             x = 1 / x;
140             n = -n;
141             }
142             while (n > 1) {
143             if (n % 2) {
144             y *= x;
145             n -= 1;
146             }
147             x *= x;
148             n /= 2;
149             }
150             (ans_datap)[0] = x * y;
151             #line 152 "lib/PDL/Ops-pp-ipow.c"
152 2 50         }PDL_BROADCASTLOOP_END_ipow_readdata
    50          
153 2           } break;
154 0           case PDL_F: {
155 0 0         PDL_DECLARE_PARAMS_ipow_1(PDL_Float,F,PDL_LongLong,Q)
    0          
    0          
    0          
    0          
    0          
    0          
    0          
    0          
156 0 0         PDL_BROADCASTLOOP_START_ipow_readdata {
    0          
    0          
    0          
    0          
    0          
    0          
157             #line 444 "lib/PDL/Ops.pd"
158              
159             PDL_LongLong n = (b_datap)[0];
160             if (n == 0) {
161             (ans_datap)[0] = 1;
162             continue;
163             }
164             PDL_Float y = 1;
165             PDL_Float x = (a_datap)[0];
166             if (n < 0) {
167             x = 1 / x;
168             n = -n;
169             }
170             while (n > 1) {
171             if (n % 2) {
172             y *= x;
173             n -= 1;
174             }
175             x *= x;
176             n /= 2;
177             }
178             (ans_datap)[0] = x * y;
179             #line 180 "lib/PDL/Ops-pp-ipow.c"
180 0 0         }PDL_BROADCASTLOOP_END_ipow_readdata
    0          
181 0           } break;
182 14           case PDL_D: {
183 14 50         PDL_DECLARE_PARAMS_ipow_1(PDL_Double,D,PDL_LongLong,Q)
    50          
    50          
    50          
    50          
    50          
    50          
    50          
    50          
184 5126 50         PDL_BROADCASTLOOP_START_ipow_readdata {
    50          
    50          
    50          
    50          
    100          
    100          
185             #line 444 "lib/PDL/Ops.pd"
186              
187             PDL_LongLong n = (b_datap)[0];
188             if (n == 0) {
189             (ans_datap)[0] = 1;
190             continue;
191             }
192             PDL_Double y = 1;
193             PDL_Double x = (a_datap)[0];
194             if (n < 0) {
195             x = 1 / x;
196             n = -n;
197             }
198             while (n > 1) {
199             if (n % 2) {
200             y *= x;
201             n -= 1;
202             }
203             x *= x;
204             n /= 2;
205             }
206             (ans_datap)[0] = x * y;
207             #line 208 "lib/PDL/Ops-pp-ipow.c"
208 300 50         }PDL_BROADCASTLOOP_END_ipow_readdata
    100          
209 14           } break;
210 0           case PDL_LD: {
211 0 0         PDL_DECLARE_PARAMS_ipow_1(PDL_LDouble,E,PDL_LongLong,Q)
    0          
    0          
    0          
    0          
    0          
    0          
    0          
    0          
212 0 0         PDL_BROADCASTLOOP_START_ipow_readdata {
    0          
    0          
    0          
    0          
    0          
    0          
213             #line 444 "lib/PDL/Ops.pd"
214              
215             PDL_LongLong n = (b_datap)[0];
216             if (n == 0) {
217             (ans_datap)[0] = 1;
218             continue;
219             }
220             PDL_LDouble y = 1;
221             PDL_LDouble x = (a_datap)[0];
222             if (n < 0) {
223             x = 1 / x;
224             n = -n;
225             }
226             while (n > 1) {
227             if (n % 2) {
228             y *= x;
229             n -= 1;
230             }
231             x *= x;
232             n /= 2;
233             }
234             (ans_datap)[0] = x * y;
235             #line 236 "lib/PDL/Ops-pp-ipow.c"
236 0 0         }PDL_BROADCASTLOOP_END_ipow_readdata
    0          
237 0           } break;
238 0           case PDL_CF: {
239 0 0         PDL_DECLARE_PARAMS_ipow_1(PDL_CFloat,G,PDL_LongLong,Q)
    0          
    0          
    0          
    0          
    0          
    0          
    0          
    0          
240 0 0         PDL_BROADCASTLOOP_START_ipow_readdata {
    0          
    0          
    0          
    0          
    0          
    0          
241             #line 444 "lib/PDL/Ops.pd"
242              
243             PDL_LongLong n = (b_datap)[0];
244             if (n == 0) {
245             (ans_datap)[0] = 1;
246             continue;
247             }
248             PDL_CFloat y = 1;
249             PDL_CFloat x = (a_datap)[0];
250             if (n < 0) {
251             x = 1 / x;
252             n = -n;
253             }
254             while (n > 1) {
255             if (n % 2) {
256             y *= x;
257             n -= 1;
258             }
259             x *= x;
260             n /= 2;
261             }
262             (ans_datap)[0] = x * y;
263             #line 264 "lib/PDL/Ops-pp-ipow.c"
264 0 0         }PDL_BROADCASTLOOP_END_ipow_readdata
    0          
265 0           } break;
266 0           case PDL_CD: {
267 0 0         PDL_DECLARE_PARAMS_ipow_1(PDL_CDouble,C,PDL_LongLong,Q)
    0          
    0          
    0          
    0          
    0          
    0          
    0          
    0          
268 0 0         PDL_BROADCASTLOOP_START_ipow_readdata {
    0          
    0          
    0          
    0          
    0          
    0          
269             #line 444 "lib/PDL/Ops.pd"
270              
271             PDL_LongLong n = (b_datap)[0];
272             if (n == 0) {
273             (ans_datap)[0] = 1;
274             continue;
275             }
276             PDL_CDouble y = 1;
277             PDL_CDouble x = (a_datap)[0];
278             if (n < 0) {
279             x = 1 / x;
280             n = -n;
281             }
282             while (n > 1) {
283             if (n % 2) {
284             y *= x;
285             n -= 1;
286             }
287             x *= x;
288             n /= 2;
289             }
290             (ans_datap)[0] = x * y;
291             #line 292 "lib/PDL/Ops-pp-ipow.c"
292 0 0         }PDL_BROADCASTLOOP_END_ipow_readdata
    0          
293 0           } break;
294 0           case PDL_CLD: {
295 0 0         PDL_DECLARE_PARAMS_ipow_1(PDL_CLDouble,H,PDL_LongLong,Q)
    0          
    0          
    0          
    0          
    0          
    0          
    0          
    0          
296 0 0         PDL_BROADCASTLOOP_START_ipow_readdata {
    0          
    0          
    0          
    0          
    0          
    0          
297             #line 444 "lib/PDL/Ops.pd"
298              
299             PDL_LongLong n = (b_datap)[0];
300             if (n == 0) {
301             (ans_datap)[0] = 1;
302             continue;
303             }
304             PDL_CLDouble y = 1;
305             PDL_CLDouble x = (a_datap)[0];
306             if (n < 0) {
307             x = 1 / x;
308             n = -n;
309             }
310             while (n > 1) {
311             if (n % 2) {
312             y *= x;
313             n -= 1;
314             }
315             x *= x;
316             n /= 2;
317             }
318             (ans_datap)[0] = x * y;
319             #line 320 "lib/PDL/Ops-pp-ipow.c"
320 0 0         }PDL_BROADCASTLOOP_END_ipow_readdata
    0          
321 0           } break;
322 0           default: return PDL->make_error(PDL_EUSERERROR, "PP INTERNAL ERROR in ipow: unhandled datatype(%d), only handles (PQFDEGCH)! PLEASE MAKE A BUG REPORT\n", __privtrans->__datatype);
323             }
324             #undef PDL_IF_BAD
325 16           return PDL_err;
326             }
327              
328             static pdl_datatypes pdl_ipow_vtable_gentypes[] = { PDL_ULL, PDL_LL, PDL_F, PDL_LD, PDL_CF, PDL_CD, PDL_CLD, PDL_D, -1 };
329             static PDL_Indx pdl_ipow_vtable_realdims[] = { 0, 0, 0 };
330             static char *pdl_ipow_vtable_parnames[] = { "a","b","ans" };
331             static short pdl_ipow_vtable_parflags[] = {
332             0,
333             PDL_PARAM_ISTYPED,
334             PDL_PARAM_ISCREAT|PDL_PARAM_ISOUT|PDL_PARAM_ISWRITE
335             };
336             static pdl_datatypes pdl_ipow_vtable_partypes[] = { -1, PDL_LL, -1 };
337             static PDL_Indx pdl_ipow_vtable_realdims_starts[] = { 0, 0, 0 };
338             static PDL_Indx pdl_ipow_vtable_realdims_ind_ids[] = { 0 };
339             static char *pdl_ipow_vtable_indnames[] = { "" };
340             pdl_transvtable pdl_ipow_vtable = {
341             PDL_TRANS_DO_BROADCAST, 0, pdl_ipow_vtable_gentypes, 2, 3, NULL /*CORE21*/,
342             pdl_ipow_vtable_realdims, pdl_ipow_vtable_parnames,
343             pdl_ipow_vtable_parflags, pdl_ipow_vtable_partypes,
344             pdl_ipow_vtable_realdims_starts, pdl_ipow_vtable_realdims_ind_ids, 0,
345             0, pdl_ipow_vtable_indnames,
346             NULL, pdl_ipow_readdata, NULL,
347             NULL,
348             0,"PDL::Ops::ipow"
349             };
350              
351              
352 16           pdl_error pdl_run_ipow(pdl *a,pdl *b,pdl *ans) {
353 16           pdl_error PDL_err = {0, NULL, 0};
354 16 50         if (!PDL) return (pdl_error){PDL_EFATAL, "PDL core struct is NULL, can't continue",0};
355 16           pdl_trans *__privtrans = PDL->create_trans(&pdl_ipow_vtable);
356 16 50         if (!__privtrans) return PDL->make_error_simple(PDL_EFATAL, "Couldn't create trans");
357 16           __privtrans->pdls[0] = a;
358 16           __privtrans->pdls[1] = b;
359 16           __privtrans->pdls[2] = ans;
360 16 50         PDL_RETERROR(PDL_err, PDL->type_coerce(__privtrans));
361 16 50         PDL_RETERROR(PDL_err, PDL->make_trans_mutual(__privtrans));
362 16           return PDL_err;
363             }