Ryu.xs

filter: Statementstmt 90.7% 205 / 226 Branchbran 89.7% 122 / 136 Conditioncond n/a MC/DCmcdc n/a Subroutinesub n/a Podpod n/a totaltotal 90.3% 327 / 362 CC 0 SCAR 0
CC
0
Cov
0%
CRAP 0
« blib/lib/Math/Ryu.pm ↑ Summary
1 #ifdef __MINGW32__
2 #ifndef __USE_MINGW_ANSI_STDIO
3 #define __USE_MINGW_ANSI_STDIO 1
4 #endif
5 #endif
6  
7 #define PERL_NO_GET_CONTEXT 1
8  
9 #include "EXTERN.h"
10 #include "perl.h"
11 #include "XSUB.h"
12  
13 #include <ryu.h>
14 #include <ryu_parse.h>
15  
16 #if defined(COMPILER_HAS_UINT128_T) && !defined(AVOID_GENERIC_128)
17 # include <generic_128.h> /* modified to include stdbool.h */
18 # include <ryu_generic_128.h>
19 # include <stdbool.h>
20 # ifdef USE_QUADMATH
21 # include <quadmath.h> /* do we actually need this ? */
22 # endif
23 #endif
24  
25 #define QUAD_MANTISSA_BITS 112
26 #define QUAD_EXPONENT_BITS 15
27  
28 #include "math_ryu_include.h"
29  
30 typedef struct floating_decimal_128 t_fd128;
31  
32 #if defined(COMPILER_HAS_UINT128_T) && !defined(AVOID_GENERIC_128) && MAX_DEC_DIG == 36
33 /* To be called only by q2s(). Cannot be accessed directly from perl */
34 struct floating_decimal_128 quad_to_fd128(NV d) {
35 uint128_t bits = 0;
36 memcpy(&bits, &d, 16);
37 return generic_binary_to_decimal(bits, QUAD_MANTISSA_BITS, QUAD_EXPONENT_BITS, false);
38 }
39 #endif
40  
41 9460 double _s2d(char * buffer) {
42 #if NVSIZE == 8
43 double nv;
44 9460 s2d(buffer, &nv);
45 9460 return nv;
46 #else
47 PERL_UNUSED_ARG(buffer);
48 croak("s2d() is available only to perls whose NV is of type 'double'");
49 #endif
50 }
51  
52 7626 SV * M_RYU_d2s(pTHX_ SV * nv) {
53 #if NVSIZE == 8
54 7626 return newSVpv(d2s(SvNV(nv)), 0);
55 #else
56 PERL_UNUSED_ARG(nv);
57 croak("d2s() is available only to perls whose NV is of type 'double'");
58 #endif
59 }
60  
61 0 SV * ld2s(pTHX_ SV * nv) {
62 #if MAX_DEC_DIG == 21
63 char * buff;
64 SV * outsv;
65  
66 Newxz(buff, LD_BUF, char); /* LD_BUF defined in math_ryu_l)include.h, along with D_BUF and F128_BUF */
67  
68 if(buff == NULL) croak("Failed to allocate memory for string buffer in ld2s sub");
69 generic_to_chars(long_double_to_fd128(SvNV(nv)), buff);
70 outsv = newSVpv(buff, 0);
71 Safefree(buff);
72 return outsv;
73 #else
74 PERL_UNUSED_ARG(nv);
75 0 croak("ld2s() is available only to perls whose NV is of type 80-bit extended precision 'long double'");
76 #endif
77 }
78  
79 0 SV * q2s(pTHX_ SV * nv) {
80 #if MAX_DEC_DIG == 36
81 char * buff;
82 SV * outsv;
83  
84 Newxz(buff, F128_BUF, char);
85  
86 if(buff == NULL) croak("Failed to allocate memory for string buffer in ld2s sub");
87 generic_to_chars(quad_to_fd128(SvNV(nv)), buff);
88 outsv = newSVpv(buff, 0);
89 Safefree(buff);
90 return outsv;
91 #else
92 PERL_UNUSED_ARG(nv);
93 0 croak("q2s() is available only to perls whose NV is either '__float128' or IEEE 754 'long double'");
94 #endif
95 }
96  
97 2 SV * fx2s(pTHX_ SV * nv) {
98 2 return newSVpv(f2s((float)SvNV(nv)), 0);
99 }
100  
101 20 int ryu_SvIOK(SV * sv) {
102 20 ▶ if(SvIOK(sv)) return 1;
Branch: 1 branch
BranchTrueFalseTotal
if(SvIOK(sv)) return 1; 2 18 20
103 18 return 0;
104 }
105  
106 7 int ryu_SvNOK(SV * sv) {
107 7 ▶ if(SvNOK(sv)) return 1;
Branch: 1 branch
BranchTrueFalseTotal
if(SvNOK(sv)) return 1; 4 3 7
108 3 return 0;
109 }
110  
111 33 int ryu_SvPOK(SV * sv) {
112 33 ▶ if(SvPOK(sv)) return 1;
Branch: 1 branch
BranchTrueFalseTotal
if(SvPOK(sv)) return 1; 17 16 33
113 16 return 0;
114 }
115  
116 0 int ryu_SvIOKp(SV * sv) {
117 0 ▶ if(SvIOKp(sv)) return 1;
Branch: 1 branch
BranchTrueFalseTotal
if(SvIOKp(sv)) return 1; 0 0 0
118 0 return 0;
119 }
120  
121 9706 int ryu_lln(pTHX_ SV * sv) {
122 9706 return looks_like_number(sv);
123 }
124  
125 14 int ryu_refcnt(SV * sv) {
126 14 return SvREFCNT(sv);
127 }
128  
129 1 int _compiler_has_uint128(void) {
130 #ifdef COMPILER_HAS_UINT128_T
131 1 return 1;
132 #else
133 return 0;
134 #endif
135 }
136  
137 1 int _get_max_dec_dig(void) {
138 #ifdef MAX_DEC_DIG
139 1 return MAX_DEC_DIG;
140 #else
141 return 0;
142 #endif
143 }
144  
145 2791 SV * fmtpy(pTHX_ SV * in) {
146 2791 int is_neg = 0, pointpos = 0, exponent, dec = 0, zero_pad = 0;
147 char *man_str, *exp_str;
148 2791 size_t i, len, seen = 0;
149 2791 char *s = SvPV_nolen(in);
150 SV * outsv;
151  
152 2791 ▶ if(s[0] == '-') {
Branch: 1 branch
BranchTrueFalseTotal
if(s[0] == '-') { 558 2233 2791
153 558 is_neg = 1;
154 558 s++;
155 }
156  
157 /* If the given argument contains a decimal point, then that *
158 * decimal point will immediately follow the first digit. *
159 * Otherwise, the argument does not contain a decimal point. */
160 2791 ▶ if(s[1] == '.') pointpos = 1;
Branch: 1 branch
BranchTrueFalseTotal
if(s[1] == '.') pointpos = 1; 2567 224 2791
161  
162 2791 ▶ if(pointpos) {
Branch: 1 branch
BranchTrueFalseTotal
if(pointpos) { 2567 224 2791
163 /*** STRING CONTAINS A DECIMAL POINT ***/
164 2567 Newxz(man_str, MAN_BUF, char);
165 2567 ▶ if(man_str == NULL) croak("Failed (in 'if' block) to allocate memory for man_str in fmtpy function");
Branch: 1 branch
BranchTrueFalseTotal
if(man_str == NULL) croak("Failed (in 'if' block) to allocate memory for man_str in fmtpy function"); 0 2567 2567
166 2567 Newxz(exp_str, EXP_BUF, char);
167 2567 ▶ if(exp_str == NULL) croak("Failed (in 'if' block) to allocate memory for exp_str in fmtpy function");
Branch: 1 branch
BranchTrueFalseTotal
if(exp_str == NULL) croak("Failed (in 'if' block) to allocate memory for exp_str in fmtpy function"); 0 2567 2567
168  
169 /* Split into mantissa and exponent around 'E' *
170 * The input string (s) has the 'E' replaced by a NULL *
171 * and the exponent portion of s is copied to exp_str */
172 2567 len = strlen(s);
173 43978 ▶ for(i = 0; i < len; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for(i = 0; i < len; i++) { 41411 2567 43978
174 41411 ▶ if(seen) { /* will be set when 'E' is encountered' */
Branch: 1 branch
BranchTrueFalseTotal
if(seen) { /* will be set when 'E' is encountered' */ 7802 33609 41411
175 7802 exp_str[i - seen] = s[i];
176 }
177 33609 ▶ else if(s[i] == 'E') {
Branch: 1 branch
BranchTrueFalseTotal
else if(s[i] == 'E') { 2567 31042 33609
178 2567 seen = i + 1;
179 2567 s[i] = '\0';
180 }
181 }
182 2567 exp_str[i - seen] = '\0';
183 2567 exponent = atoi(exp_str);
184  
185 2567 ▶ if(exponent > 0 && exponent < MAX_DEC_DIG) {
Branch: 2 branches
BranchTrueFalseTotal
if(exponent > 0 && exponent < MAX_DEC_DIG) { 1205 1362 2567
if(exponent > 0 && exponent < MAX_DEC_DIG) { 165 1040 1205
186 165 len = strlen(s);
187 165 zero_pad = exponent - ((int)len - 2);
188 165 ▶ if(zero_pad >= 0 && (zero_pad + len < MAX_DEC_DIG + 1)) {
Branch: 2 branches
BranchTrueFalseTotal
if(zero_pad >= 0 && (zero_pad + len < MAX_DEC_DIG + 1)) { 79 86 165
if(zero_pad >= 0 && (zero_pad + len < MAX_DEC_DIG + 1)) { 63 16 79
189 /* Return, eg, '1.23E15' as '1230000000000000.0' */
190 63 ▶ if(is_neg) man_str[0] = '-';
Branch: 1 branch
BranchTrueFalseTotal
if(is_neg) man_str[0] = '-'; 13 50 63
191 63 man_str[0 + is_neg] = s[0];
192 675 ▶ for(i = 2; i < len; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for(i = 2; i < len; i++) { 612 63 675
193 612 man_str[i + is_neg - 1] = s[i];
194 }
195 231 ▶ for(dec = 0; dec < zero_pad; dec++) {
Branch: 1 branch
BranchTrueFalseTotal
for(dec = 0; dec < zero_pad; dec++) { 168 63 231
196 168 man_str[i + is_neg - 1] = '0';
197 168 i++;
198 }
199 63 man_str[i + is_neg - 1] = '.';
200 63 man_str[i + is_neg] = '0';
201 63 man_str[i + is_neg + 1] = '\0';
202  
203 63 outsv = newSVpv(man_str, 0);
204 63 Safefree(man_str);
205 63 Safefree(exp_str);
206 63 ▶ if(is_neg) s--;
Branch: 1 branch
BranchTrueFalseTotal
if(is_neg) s--; 13 50 63
207 63 return outsv;
208 }
209 102 ▶ else if(zero_pad < 0) {
Branch: 1 branch
BranchTrueFalseTotal
else if(zero_pad < 0) { 86 16 102
210 /* We want, eg, 1.23625E2 to be returned as "123.625". *
211 * This involves relocation of the decimal point. */
212 86 len = strlen(s);
213 86 zero_pad--;
214 86 ▶ if(is_neg) man_str[0] = '-';
Branch: 1 branch
BranchTrueFalseTotal
if(is_neg) man_str[0] = '-'; 17 69 86
215 86 man_str[0 + is_neg] = s[0];
216 86 man_str[1 + is_neg] = s[2]; /* s[1] is the decimal point */
217 86 dec = 1; /* set to 0 when the decimal point is encountered */
218 958 ▶ for(i = 2; i < len; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for(i = 2; i < len; i++) { 872 86 958
219 872 ▶ if(i == zero_pad + len) {
Branch: 1 branch
BranchTrueFalseTotal
if(i == zero_pad + len) { 86 786 872
220 86 man_str[i + is_neg] = '.';
221 86 dec--;
222 }
223 786 else man_str[i + is_neg] = s[i + dec];
224 }
225  
226 86 man_str[i + is_neg] = '\0';
227  
228 86 outsv = newSVpv(man_str, 0);
229 86 Safefree(man_str);
230 86 Safefree(exp_str);
231 86 ▶ if(is_neg) s--;
Branch: 1 branch
BranchTrueFalseTotal
if(is_neg) s--; 17 69 86
232 86 return outsv;
233 }
234 }
235  
236 2418 len = strlen(s); /* now different to when initially set *
237 * because 'E' has been replaced with '\0' */
238 2418 ▶ if(exponent < -4 || exponent >= 0) {
Branch: 2 branches
BranchTrueFalseTotal
if(exponent < -4 || exponent >= 0) { 1127 1291 2418
if(exponent < -4 || exponent >= 0) { 1071 56 1127
239 2362 ▶ if(is_neg) man_str[0] = '-';
Branch: 1 branch
BranchTrueFalseTotal
if(is_neg) man_str[0] = '-'; 470 1892 2362
240 30864 ▶ for(i = 0; i < len; i++) man_str[i + is_neg] = s[i];
Branch: 1 branch
BranchTrueFalseTotal
for(i = 0; i < len; i++) man_str[i + is_neg] = s[i]; 28502 2362 30864
241 2362 ▶ if(!exponent) {
Branch: 1 branch
BranchTrueFalseTotal
if(!exponent) { 15 2347 2362
242 15 man_str[i + is_neg] = '\0';
243 15 outsv = newSVpv(man_str, 0);
244 15 Safefree(man_str);
245 15 Safefree(exp_str);
246 15 ▶ if(is_neg) s--;
Branch: 1 branch
BranchTrueFalseTotal
if(is_neg) s--; 2 13 15
247 15 return outsv;
248 }
249 2347 man_str[i + is_neg] = 'e';
250 2347 len = strlen(exp_str);
251 2347 ▶ if(exponent > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if(exponent > 0) { 1056 1291 2347
252 1056 man_str[i + 1 + is_neg] = '+';
253 1056 dec = (int)i + 2 + is_neg;
254 3868 ▶ for(i = 0; i < len; i ++) man_str[dec + i] = exp_str[i];
Branch: 1 branch
BranchTrueFalseTotal
for(i = 0; i < len; i ++) man_str[dec + i] = exp_str[i]; 2812 1056 3868
255 1056 man_str[dec + i] = '\0';
256 1056 outsv = newSVpv(man_str, 0);
257 1056 Safefree(man_str);
258 1056 Safefree(exp_str);
259 1056 ▶ if(is_neg) s--;
Branch: 1 branch
BranchTrueFalseTotal
if(is_neg) s--; 212 844 1056
260 1056 return outsv;
261 }
262 /* exponent < -4 */
263 1291 dec = (int)i + 1 + is_neg;
264 1291 ▶ if(len == 2) {
Branch: 1 branch
BranchTrueFalseTotal
if(len == 2) { 53 1238 1291
265 53 man_str[dec] = '-';
266 53 man_str[dec + 1] = '0';
267 53 man_str[dec + 2] = exp_str[1];
268 53 man_str[dec + 3] = '\0';
269 }
270 else {
271 5783 ▶ for(i = 0; i < len; i++) man_str[dec + i] = exp_str[i];
Branch: 1 branch
BranchTrueFalseTotal
for(i = 0; i < len; i++) man_str[dec + i] = exp_str[i]; 4545 1238 5783
272 1238 man_str[dec + i] = '\0';
273 }
274 1291 outsv = newSVpv(man_str, 0);
275 1291 Safefree(man_str);
276 1291 Safefree(exp_str);
277 1291 ▶ if(is_neg) s--;
Branch: 1 branch
BranchTrueFalseTotal
if(is_neg) s--; 256 1035 1291
278 1291 return outsv;
279 }
280 /* exponent is in range -1 to -4 (inclusive). *
281 * Return, eg 6.25E1 as "0.625". **************/
282 56 ▶ if(is_neg) man_str[0] = '-';
Branch: 1 branch
BranchTrueFalseTotal
if(is_neg) man_str[0] = '-'; 10 46 56
283 56 man_str[is_neg] = '0';
284 56 man_str[1 + is_neg] = '.';
285 56 zero_pad = -exponent;
286 56 zero_pad --;
287 109 ▶ for(i = 0; i < (size_t)zero_pad; i++) man_str[i + 2 + is_neg] = '0';
Branch: 1 branch
BranchTrueFalseTotal
for(i = 0; i < (size_t)zero_pad; i++) man_str[i + 2 + is_neg] = '0'; 53 56 109
288 56 man_str[i + 2 + is_neg] = s[0];
289 56 dec = (int)i + 1 + is_neg;
290 56 len = strlen(s);
291 702 ▶ for(i = 2; i < len; i++) man_str[dec + i] = s[i];
Branch: 1 branch
BranchTrueFalseTotal
for(i = 2; i < len; i++) man_str[dec + i] = s[i]; 646 56 702
292 56 man_str[dec + i] = '\0';
293 56 outsv = newSVpv(man_str, 0);
294 56 Safefree(man_str);
295 56 Safefree(exp_str);
296 56 ▶ if(is_neg) s--;
Branch: 1 branch
BranchTrueFalseTotal
if(is_neg) s--; 10 46 56
297 56 return outsv;
298 }
299 else {
300 /*** NO DECIMAL POINT IN STRING ***/
301 224 ▶ if(s[0] == 'I') {
Branch: 1 branch
BranchTrueFalseTotal
if(s[0] == 'I') { 193 31 224
302 193 ▶ if(is_neg) {
Branch: 1 branch
BranchTrueFalseTotal
if(is_neg) { 38 155 193
303 38 s--;
304 /* if(SvIV(get_sv("Math::Ryu::PERL_INFNAN", 0))) return newSVpv(SvPV_nolen(get_sv("Math::Ryu::ninfstr", 0)), 0); */
305 38 ▶ if(SvIV(get_sv("Math::Ryu::PERL_INFNAN", 0))) {
Branch: 1 branch
BranchTrueFalseTotal
if(SvIV(get_sv("Math::Ryu::PERL_INFNAN", 0))) { 1 37 38
306 1 outsv = SvREFCNT_inc(get_sv("Math::Ryu::ninfstr", 0));
307 1 return outsv;
308 }
309 37 return newSVpv("-inf", 0);
310 }
311 else {
312 /* if(SvIV(get_sv("Math::Ryu::PERL_INFNAN", 0))) return newSVpv(SvPV_nolen(get_sv("Math::Ryu::pinfstr", 0)), 0); */
313 155 ▶ if(SvIV(get_sv("Math::Ryu::PERL_INFNAN", 0))) {
Branch: 1 branch
BranchTrueFalseTotal
if(SvIV(get_sv("Math::Ryu::PERL_INFNAN", 0))) { 1 154 155
314 1 outsv = SvREFCNT_inc(get_sv("Math::Ryu::pinfstr", 0));
315 1 return outsv;
316 }
317 154 return newSVpv("inf", 0);
318 }
319 }
320 31 ▶ if(s[0] == 'N') {
Branch: 1 branch
BranchTrueFalseTotal
if(s[0] == 'N') { 3 28 31
321 3 ▶ if(is_neg) {
Branch: 1 branch
BranchTrueFalseTotal
if(is_neg) { 0 3 3
322 0 s--;
323 0 croak("rubbish input of '%s'", s);
324 }
325 /* if(SvIV(get_sv("Math::Ryu::PERL_INFNAN", 0))) return newSVpv(SvPV_nolen(get_sv("Math::Ryu::nanvstr", 0)), 0); */
326 3 ▶ if(SvIV(get_sv("Math::Ryu::PERL_INFNAN", 0))) {
Branch: 1 branch
BranchTrueFalseTotal
if(SvIV(get_sv("Math::Ryu::PERL_INFNAN", 0))) { 2 1 3
327 2 outsv = SvREFCNT_inc(get_sv("Math::Ryu::nanvstr", 0));
328 2 return outsv;
329 }
330 1 return newSVpv("nan", 0);
331 }
332 /* mantissa is single-digit */
333 28 len = strlen(s);
334 28 Newxz(exp_str, MAX_DEC_DIG + 6, char);
335 28 ▶ if(exp_str == NULL) croak("Failed (in 'else' block) to allocate memory for exp_str in fmtpy function");
Branch: 1 branch
BranchTrueFalseTotal
if(exp_str == NULL) croak("Failed (in 'else' block) to allocate memory for exp_str in fmtpy function"); 0 28 28
336 134 ▶ for(i = 2; i <= len; i++) exp_str[i - 2] = s[i];
Branch: 1 branch
BranchTrueFalseTotal
for(i = 2; i <= len; i++) exp_str[i - 2] = s[i]; 106 28 134
337 28 exponent = atoi(exp_str);
338 28 ▶ if(exponent < -9) {
Branch: 1 branch
BranchTrueFalseTotal
if(exponent < -9) { 14 14 28
339 /* Return, eg, '5E-10' as '5e-10' */
340 14 s[1] = 'e';
341 14 ▶ if(is_neg) s--;
Branch: 1 branch
BranchTrueFalseTotal
if(is_neg) s--; 5 9 14
342 14 Safefree(exp_str);
343 14 return newSVpv(s, 0);
344 }
345 /* Put the string to return into exp_str */
346 14 ▶ if(exponent < -4) {
Branch: 1 branch
BranchTrueFalseTotal
if(exponent < -4) { 2 12 14
347 /* Return, eg, '5E-9' as '5e-09'. */
348 2 ▶ if(is_neg) exp_str[0] = '-';
Branch: 1 branch
BranchTrueFalseTotal
if(is_neg) exp_str[0] = '-'; 1 1 2
349 2 exp_str[0 + is_neg] = s[0];
350 2 exp_str[1 + is_neg] = 'e';
351 2 exp_str[2 + is_neg] = '-';
352 2 exp_str[3 + is_neg] = '0';
353 2 exp_str[4 + is_neg] = s[3];
354 2 exp_str[5 + is_neg] = '\0';
355 2 outsv = newSVpv(exp_str, 0);
356 2 Safefree(exp_str);
357 2 ▶ if(is_neg) s--;
Branch: 1 branch
BranchTrueFalseTotal
if(is_neg) s--; 1 1 2
358 2 return outsv;
359 }
360  
361 12 ▶ if(exponent >= 0 && exponent <= MAX_DEC_DIG - 2) {
Branch: 2 branches
BranchTrueFalseTotal
if(exponent >= 0 && exponent <= MAX_DEC_DIG - 2) { 12 0 12
if(exponent >= 0 && exponent <= MAX_DEC_DIG - 2) { 8 4 12
362 /* Return, eg, '5E13' as '50000000000000.0' */
363 8 ▶ if(is_neg) exp_str[0] = '-';
Branch: 1 branch
BranchTrueFalseTotal
if(is_neg) exp_str[0] = '-'; 2 6 8
364 8 exp_str[0 + is_neg] = s[0];
365 56 ▶ for(dec = 0; dec < exponent; dec++) exp_str[1 + is_neg + dec] = '0';
Branch: 1 branch
BranchTrueFalseTotal
for(dec = 0; dec < exponent; dec++) exp_str[1 + is_neg + dec] = '0'; 48 8 56
366 8 exp_str[1 + is_neg + dec] = '.';
367 8 exp_str[2 + is_neg + dec] = '0';
368 8 exp_str[3 + is_neg + dec] = '\0';
369  
370 8 outsv = newSVpv(exp_str, 0);
371 8 Safefree(exp_str);
372 8 ▶ if(is_neg) s--;
Branch: 1 branch
BranchTrueFalseTotal
if(is_neg) s--; 2 6 8
373 8 return outsv;
374 }
375  
376 4 ▶ if(exponent > MAX_DEC_DIG - 2) {
Branch: 1 branch
BranchTrueFalseTotal
if(exponent > MAX_DEC_DIG - 2) { 4 0 4
377 /* Return, eg, '8E50' as '8e+50' */
378 4 ▶ if(is_neg) exp_str[0] = '-';
Branch: 1 branch
BranchTrueFalseTotal
if(is_neg) exp_str[0] = '-'; 2 2 4
379 4 exp_str[0 + is_neg] = s[0];
380 4 exp_str[1 + is_neg] = 'e';
381 4 exp_str[2 + is_neg] = '+';
382 12 ▶ for(i = 2; i < len; i++) exp_str[i + 1 + is_neg] = s[i];
Branch: 1 branch
BranchTrueFalseTotal
for(i = 2; i < len; i++) exp_str[i + 1 + is_neg] = s[i]; 8 4 12
383 4 exp_str[i + 1 + is_neg] = '\0';
384 4 outsv = newSVpv(exp_str, 0);
385 4 Safefree(exp_str);
386 4 ▶ if(is_neg) s--;
Branch: 1 branch
BranchTrueFalseTotal
if(is_neg) s--; 2 2 4
387 4 return outsv;
388 }
389  
390 /* Exponent is in the range -1 to -4. We *
391 * want, eg, '7E-1' to be returned as '0.7' *
392 * and '-9E-4' to be returned as '-0.0009' */
393  
394 0 ▶ if(is_neg) exp_str[0] = '-';
Branch: 1 branch
BranchTrueFalseTotal
if(is_neg) exp_str[0] = '-'; 0 0 0
395 0 exp_str[0 + is_neg] = '0';
396 0 exp_str[1 + is_neg] = '.';
397 0 ▶ for(dec = -1; dec > exponent; dec--) exp_str[1 + is_neg - dec] = '0';
Branch: 1 branch
BranchTrueFalseTotal
for(dec = -1; dec > exponent; dec--) exp_str[1 + is_neg - dec] = '0'; 0 0 0
398 0 exp_str[1 + is_neg - dec] = s[0];
399 0 exp_str[2 + is_neg - dec] = '\0';
400  
401 0 outsv = newSVpv(exp_str, 0);
402 0 Safefree(exp_str);
403 0 ▶ if(is_neg) s--;
Branch: 1 branch
BranchTrueFalseTotal
if(is_neg) s--; 0 0 0
404 0 return outsv;
405 }
406 }
407  
408 3 SV * _from_NV(pTHX_ NV arg ) {
409 3 ▶ if(arg >= 0) {
Branch: 1 branch
BranchTrueFalseTotal
if(arg >= 0) { 1 2 3
410 1 return newSVuv((UV)arg);
411 }
412 2 return newSViv((IV)arg);
413 }
414  
415  
416 MODULE = Math::Ryu PACKAGE = Math::Ryu PREFIX = M_RYU_
417  
418 PROTOTYPES: DISABLE
419  
420 double
421 _s2d (buffer)
422 char * buffer
423  
424 SV *
425 M_RYU_d2s (nv)
426 SV * nv
427 CODE:
428 7626 RETVAL = M_RYU_d2s (aTHX_ nv);
429 OUTPUT: RETVAL
430  
431 SV *
432 ld2s (nv)
433 SV * nv
434 CODE:
435 0 RETVAL = ld2s (aTHX_ nv);
436 OUTPUT: RETVAL
437  
438 SV *
439 q2s (nv)
440 SV * nv
441 CODE:
442 0 RETVAL = q2s (aTHX_ nv);
443 OUTPUT: RETVAL
444  
445 SV *
446 fx2s (nv)
447 SV * nv
448 CODE:
449 2 RETVAL = fx2s (aTHX_ nv);
450 OUTPUT: RETVAL
451  
452 int
453 ryu_SvIOK (sv)
454 SV * sv
455  
456 int
457 ryu_SvNOK (sv)
458 SV * sv
459  
460 int
461 ryu_SvPOK (sv)
462 SV * sv
463  
464 int
465 ryu_SvIOKp (sv)
466 SV * sv
467  
468 int
469 ryu_lln (sv)
470 SV * sv
471 CODE:
472 9706 RETVAL = ryu_lln (aTHX_ sv);
473 OUTPUT: RETVAL
474  
475 int
476 ryu_refcnt (sv)
477 SV * sv
478  
479 int
480 _compiler_has_uint128 ()
481  
482 int
483 _get_max_dec_dig ()
484  
485 SV *
486 fmtpy (in)
487 SV * in
488 CODE:
489 2791 RETVAL = fmtpy (aTHX_ in);
490 OUTPUT: RETVAL
491  
492 SV *
493 _from_NV (arg)
494 NV arg
495 CODE:
496 3 RETVAL = _from_NV (aTHX_ arg);
497 OUTPUT: RETVAL
498  
499  
« blib/lib/Math/Ryu.pm ↑ Summary