File Coverage

blib/lib/Math/Float128.pm
Criterion Covered Total %
statement 74 83 89.1
branch 36 42 85.7
condition 3 6 50.0
subroutine 31 31 100.0
pod 0 3 0.0
total 144 165 87.2


line stmt bran cond sub pod time code
1             ## This file generated by InlineX::C2XS (version 0.22) using Inline::C (version 0.53)
2             package Math::Float128;
3 22     22   9182 use warnings;
  22         131  
  22         607  
4 22     22   100 use strict;
  22         31  
  22         6039  
5              
6             require Exporter;
7             *import = \&Exporter::import;
8             require DynaLoader;
9              
10             use overload
11 22         421 '+' => \&_overload_add,
12             '*' => \&_overload_mul,
13             '-' => \&_overload_sub,
14             '/' => \&_overload_div,
15             '**' => \&_overload_pow,
16             '+=' => \&_overload_add_eq,
17             '*=' => \&_overload_mul_eq,
18             '-=' => \&_overload_sub_eq,
19             '/=' => \&_overload_div_eq,
20             '**=' => \&_overload_pow_eq,
21             '==' => \&_overload_equiv,
22             '""' => \&_overload_string,
23             '!=' => \&_overload_not_equiv,
24             'bool' => \&_overload_true,
25             '!' => \&_overload_not,
26             '=' => \&_overload_copy,
27             '<' => \&_overload_lt,
28             '<=' => \&_overload_lte,
29             '>' => \&_overload_gt,
30             '>=' => \&_overload_gte,
31             '<=>' => \&_overload_spaceship,
32             'abs' => \&_overload_abs,
33             'int' => \&_overload_int,
34             'sqrt' => \&_overload_sqrt,
35             'log' => \&_overload_log,
36             'exp' => \&_overload_exp,
37             'sin' => \&_overload_sin,
38             'cos' => \&_overload_cos,
39             'atan2' => \&_overload_atan2,
40             '++' => \&_overload_inc,
41             '--' => \&_overload_dec,
42 22     22   22063 ;
  22         19426  
43              
44 22         112 use subs qw(FLT128_DIG FLT128_MANT_DIG FLT128_MIN_EXP FLT128_MAX_EXP FLT128_MIN_10_EXP FLT128_MAX_10_EXP
45             M_Eq M_LOG2Eq M_LOG10Eq M_LN2q M_LN10q M_PIq M_PI_2q M_PI_4q M_1_PIq M_2_PIq
46             M_2_SQRTPIq M_SQRT2q M_SQRT1_2q
47 22     22   17323 FLT128_MAX FLT128_MIN FLT128_EPSILON FLT128_DENORM_MIN);
  22         543  
48              
49             $Math::Float128::VERSION = '0.14';
50              
51             Math::Float128->DynaLoader::bootstrap($Math::Float128::VERSION);
52              
53             @Math::Float128::EXPORT = ();
54             @Math::Float128::EXPORT_OK = qw(
55             flt128_set_prec flt128_get_prec InfF128 NaNF128 ZeroF128 UnityF128 is_NaNF128
56             is_InfF128 is_InfF128 is_ZeroF128 STRtoF128 NVtoF128 IVtoF128 UVtoF128 F128toSTR
57             F128toSTRP F128toF128 F128toNV
58             FLT128_DIG FLT128_MANT_DIG FLT128_MIN_EXP FLT128_MAX_EXP FLT128_MIN_10_EXP FLT128_MAX_10_EXP
59             M_Eq M_LOG2Eq M_LOG10Eq M_LN2q M_LN10q M_PIq M_PI_2q M_PI_4q M_1_PIq M_2_PIq
60             M_2_SQRTPIq M_SQRT2q M_SQRT1_2q
61             FLT128_MAX FLT128_MIN FLT128_EPSILON FLT128_DENORM_MIN
62             cmp2NV f128_bytes
63             acos_F128 acosh_F128 asin_F128 asinh_F128 atan_F128 atanh_F128 atan2_F128 cbrt_F128 ceil_F128
64             copysign_F128 cosh_F128 cos_F128 erf_F128 erfc_F128 exp_F128 expm1_F128 fabs_F128 fdim_F128
65             finite_F128 floor_F128 fma_F128 fmax_F128 fmin_F128 fmod_F128 frexp_F128 hypot_F128 isinf_F128
66             ilogb_F128 isnan_F128 j0_F128 j1_F128 jn_F128 ldexp_F128 lgamma_F128 llrint_F128 llround_F128
67             log_F128 log10_F128 log2_F128 log1p_F128 lrint_F128 lround_F128 modf_F128 nan_F128
68             nearbyint_F128 nextafter_F128 pow_F128 remainder_F128 remquo_F128 rint_F128 round_F128
69             scalbln_F128 scalbn_F128 signbit_F128 sincos_F128 sinh_F128 sin_F128 sqrt_F128 tan_F128
70             tanh_F128 tgamma_F128 trunc_F128 y0_F128 y1_F128 yn_F128
71             fromSTR fromNV fromIV fromUV fromF128
72             );
73              
74             %Math::Float128::EXPORT_TAGS = (all => [qw(
75             flt128_set_prec flt128_get_prec InfF128 NaNF128 ZeroF128 UnityF128 is_NaNF128
76             is_InfF128 is_InfF128 is_ZeroF128 STRtoF128 NVtoF128 IVtoF128 UVtoF128 F128toSTR
77             F128toSTRP F128toF128 F128toNV
78             FLT128_DIG FLT128_MANT_DIG FLT128_MIN_EXP FLT128_MAX_EXP FLT128_MIN_10_EXP FLT128_MAX_10_EXP
79             M_Eq M_LOG2Eq M_LOG10Eq M_LN2q M_LN10q M_PIq M_PI_2q M_PI_4q M_1_PIq M_2_PIq
80             M_2_SQRTPIq M_SQRT2q M_SQRT1_2q
81             FLT128_MAX FLT128_MIN FLT128_EPSILON FLT128_DENORM_MIN
82             cmp2NV f128_bytes
83             acos_F128 acosh_F128 asin_F128 asinh_F128 atan_F128 atanh_F128 atan2_F128 cbrt_F128 ceil_F128
84             copysign_F128 cosh_F128 cos_F128 erf_F128 erfc_F128 exp_F128 expm1_F128 fabs_F128 fdim_F128
85             finite_F128 floor_F128 fma_F128 fmax_F128 fmin_F128 fmod_F128 frexp_F128 hypot_F128 isinf_F128
86             ilogb_F128 isnan_F128 j0_F128 j1_F128 jn_F128 ldexp_F128 lgamma_F128 llrint_F128 llround_F128
87             log_F128 log10_F128 log2_F128 log1p_F128 lrint_F128 lround_F128 modf_F128 nan_F128
88             nearbyint_F128 nextafter_F128 pow_F128 remainder_F128 remquo_F128 rint_F128 round_F128
89             scalbln_F128 scalbn_F128 signbit_F128 sincos_F128 sinh_F128 sin_F128 sqrt_F128 tan_F128
90             tanh_F128 tgamma_F128 trunc_F128 y0_F128 y1_F128 yn_F128
91             fromSTR fromNV fromIV fromUV fromF128
92             )]);
93              
94             $Math::Float128::NOK_POK = 0; # Set to 1 to allow warnings in new() and overloaded operations when
95             # a scalar that has set both NOK (NV) and POK (PV) flags is encountered
96              
97 22     22 0 16057 sub dl_load_flags {0} # Prevent DynaLoader from complaining and croaking
98              
99             sub _overload_string {
100              
101 7 100   7   176 if(is_ZeroF128($_[0])) {
102 4 100       13 return '-0' if is_ZeroF128($_[0]) < 0;
103 2         5 return '0';
104             }
105              
106 3 100       8 if(is_NaNF128($_[0])) {return 'NaN'}
  1         2  
107              
108 2         4 my $inf = is_InfF128($_[0]);
109 2 100       15 return '-Inf' if $inf < 0;
110 1 50       4 return 'Inf' if $inf > 0;
111              
112 0         0 my @p = split /e/i, F128toSTR($_[0]);
113 0   0     0 while(substr($p[0], -1, 1) eq '0' && substr($p[0], -2, 1) ne '.') {
114 0         0 chop $p[0];
115             }
116 0         0 return $p[0] . 'e' . $p[1];
117             }
118              
119             sub new {
120              
121             # This function caters for 2 possibilities:
122             # 1) that 'new' has been called as a method - in which
123             # case there will be a maximum of 2 args
124             # 2) that 'new' has been called as a function - in
125             # which case there will be a maximum of 1 arg.
126             # If there are no args, then we just want to return a
127             # Math::Float128 object that's a NaN.
128              
129 442 50   442 0 7135 if(!@_) {return NaNF128()}
  0         0  
130              
131 442 50       675 if(@_ > 2) {die "More than 2 arguments supplied to new()"}
  0         0  
132              
133             # If 'new' has been called OOP style, the first arg is the string
134             # "Math::Float128" which we don't need - so let's remove it. However,
135             # if the first arg is a Math::Float128 object (which is a possibility),
136             # then we'll get a fatal error when we check it for equivalence to
137             # the string "Math::Float128". So we first need to check that it's
138             # not an object - which we'll do by using the ref() function:
139 442 100 100     1162 if(!ref($_[0]) && $_[0] eq "Math::Float128") {
140 436         491 shift;
141 436 100       787 if(!@_) {return NaNF128()}
  8         59  
142             }
143              
144 434 50       612 if(@_ > 1) {die "Too many arguments supplied to new() - expected no more than 1"}
  0         0  
145              
146 434         517 my $arg = shift;
147 434         1050 my $type = _itsa($arg);
148              
149 434 100       874 return UVtoF128 ($arg) if $type == 1; #UV
150 409 100       1357 return IVtoF128 ($arg) if $type == 2; #IV
151              
152 262 100       359 if($type == 4) { #PV
153 95 100       212 if(_SvNOK($arg)) {
154 3         10 set_nok_pok(nok_pokflag() + 1);
155 3 50       6 if($Math::MPFR::NOK_POK) {
156 0         0 warn "Scalar passed to new() is both NV and PV. Using PV (string) value";
157             }
158             }
159 95         589 return STRtoF128($arg);
160             }
161              
162 167 100       249 if($type == 3) { # NV
163 141 100       290 if($arg == 0) {return NVtoF128($arg)}
  2         7  
164 139 100       244 if($arg != $arg) { return NaNF128()}
  2         13  
165 137 100       352 if(($arg / $arg) != 1) { # Inf
166 4 100       8 if($arg < 0) {return InfF128(-1)}
  2         13  
167 2         19 return InfF128(1);
168             }
169 133         914 return NVtoF128($arg);
170             }
171              
172 26 50       46 if($type == 113) { # Math::Float128
173 26         105 return F128toF128($arg);
174             }
175              
176 0         0 die "Bad argument given to new";
177             }
178              
179              
180             sub f128_bytes {
181 1     1 0 92 my @ret = _f128_bytes($_[0]);
182 1         7 return join '', @ret;
183             }
184              
185 2     2   154 sub FLT128_DIG () {return _FLT128_DIG()}
186 1     1   36 sub FLT128_MAX () {return _FLT128_MAX()}
187 1     1   47 sub FLT128_MIN () {return _FLT128_MIN()}
188 1     1   18 sub FLT128_EPSILON () {return _FLT128_EPSILON()}
189 1     1   39 sub FLT128_DENORM_MIN () {return _FLT128_DENORM_MIN()}
190 1     1   22 sub FLT128_MANT_DIG () {return _FLT128_MANT_DIG()}
191 1     1   38 sub FLT128_MIN_EXP () {return _FLT128_MIN_EXP()}
192 1     1   13 sub FLT128_MAX_EXP () {return _FLT128_MAX_EXP()}
193 1     1   10 sub FLT128_MIN_10_EXP () {return _FLT128_MIN_10_EXP()}
194 1     1   10 sub FLT128_MAX_10_EXP () {return _FLT128_MAX_10_EXP()}
195 1     1   34 sub M_Eq () {return _M_Eq()}
196 1     1   18 sub M_LOG2Eq () {return _M_LOG2Eq()}
197 1     1   15 sub M_LOG10Eq () {return _M_LOG10Eq()}
198 1     1   14 sub M_LN2q () {return _M_LN2q()}
199 1     1   14 sub M_LN10q () {return _M_LN10q()}
200 1     1   15 sub M_PIq () {return _M_PIq()}
201 1     1   15 sub M_PI_2q () {return _M_PI_2q()}
202 1     1   15 sub M_PI_4q () {return _M_PI_4q()}
203 1     1   26 sub M_1_PIq () {return _M_1_PIq()}
204 1     1   41 sub M_2_PIq () {return _M_2_PIq()}
205 1     1   25 sub M_2_SQRTPIq () {return _M_2_SQRTPIq()}
206 1     1   14 sub M_SQRT2q () {return _M_SQRT2q()}
207 1     1   24 sub M_SQRT1_2q () {return _M_SQRT1_2q()}
208              
209             1;
210