File Coverage

blib/lib/Math/LongDouble.pm
Criterion Covered Total %
statement 16 101 15.8
branch 0 38 0.0
condition 0 6 0.0
subroutine 6 46 13.0
pod n/a
total 22 191 11.5


line stmt bran cond sub pod time code
1             ## This file generated by InlineX::C2XS (version 0.22) using Inline::C (version 0.5002)
2             package Math::LongDouble;
3 21     21   14758 use warnings;
  21         173  
  21         620  
4 21     21   102 use strict;
  21         64  
  21         383  
5 21     21   5791 use POSIX;
  21         126110  
  21         121  
6              
7             require Exporter;
8             *import = \&Exporter::import;
9             require DynaLoader;
10              
11             use overload
12 21         542 '+' => \&_overload_add,
13             '*' => \&_overload_mul,
14             '-' => \&_overload_sub,
15             '/' => \&_overload_div,
16             '**' => \&_overload_pow,
17             '+=' => \&_overload_add_eq,
18             '*=' => \&_overload_mul_eq,
19             '-=' => \&_overload_sub_eq,
20             '/=' => \&_overload_div_eq,
21             '**=' => \&_overload_pow_eq,
22             '==' => \&_overload_equiv,
23             '""' => \&_overload_string,
24             '!=' => \&_overload_not_equiv,
25             'bool' => \&_overload_true,
26             '!' => \&_overload_not,
27             '=' => \&_overload_copy,
28             '<' => \&_overload_lt,
29             '<=' => \&_overload_lte,
30             '>' => \&_overload_gt,
31             '>=' => \&_overload_gte,
32             '<=>' => \&_overload_spaceship,
33             'abs' => \&_overload_abs,
34             'int' => \&_overload_int,
35             'sqrt' => \&_overload_sqrt,
36             'log' => \&_overload_log,
37             'exp' => \&_overload_exp,
38             'sin' => \&_overload_sin,
39             'cos' => \&_overload_cos,
40             'atan2' => \&_overload_atan2,
41             '++' => \&_overload_inc,
42             '--' => \&_overload_dec,
43 21     21   76098 ;
  21         17267  
44              
45 21         111 use subs qw(
46             LD_DBL_DIG LD_LDBL_DIG LD_DBL_MANT_DIG LD_LDBL_MANT_DIG
47              
48             LD_DBL_MIN_EXP LD_DBL_MAX_EXP LD_DBL_MIN_10_EXP LD_DBL_MAX_10_EXP
49             LD_DBL_MAX LD_DBL_MIN LD_DBL_EPSILON LD_DBL_DENORM_MIN
50              
51             LD_LDBL_MIN_EXP LD_LDBL_MAX_EXP LD_LDBL_MIN_10_EXP LD_LDBL_MAX_10_EXP
52             LD_LDBL_MAX LD_LDBL_MIN LD_LDBL_EPSILON LD_LDBL_DENORM_MIN
53              
54             M_El M_LOG2El M_LOG10El M_LN2l M_LN10l M_PIl M_PI_2l M_PI_4l
55             M_1_PIl M_2_PIl M_2_SQRTPIl M_SQRT2l M_SQRT1_2l
56 21     21   14476 );
  21         565  
57              
58             our $VERSION = '0.19';
59             #$VERSION = eval $VERSION;
60              
61             DynaLoader::bootstrap Math::LongDouble $Math::LongDouble::VERSION;
62              
63             @Math::LongDouble::EXPORT = ();
64             @Math::LongDouble::EXPORT_OK = qw(
65             InfLD NaNLD ZeroLD UnityLD is_NaNLD is_InfLD is_ZeroLD STRtoLD LDtoSTR NVtoLD UVtoLD IVtoLD
66             LDtoNV LDtoLD cmp_NV
67             ld_set_prec ld_get_prec LDtoSTRP
68             LD_DBL_DIG LD_LDBL_DIG LD_DBL_MANT_DIG LD_LDBL_MANT_DIG
69              
70             LD_DBL_MIN_EXP LD_DBL_MAX_EXP LD_DBL_MIN_10_EXP LD_DBL_MAX_10_EXP
71             LD_DBL_MAX LD_DBL_MIN LD_DBL_EPSILON LD_DBL_DENORM_MIN
72              
73             LD_LDBL_MIN_EXP LD_LDBL_MAX_EXP LD_LDBL_MIN_10_EXP LD_LDBL_MAX_10_EXP
74             LD_LDBL_MAX LD_LDBL_MIN LD_LDBL_EPSILON LD_LDBL_DENORM_MIN
75              
76             M_El M_LOG2El M_LOG10El M_LN2l M_LN10l M_PIl M_PI_2l M_PI_4l
77             M_1_PIl M_2_PIl M_2_SQRTPIl M_SQRT2l M_SQRT1_2l
78              
79             ld_max_orig_len ld_min_inter_prec ld_min_inter_base ld_max_orig_base ld_bytes
80              
81             llrint_LD llround_LD lrint_LD lround_LD frexp_LD nan_LD remquo_LD
82             acos_LD acosh_LD asin_LD asinh_LD atan_LD atanh_LD atan2_LD cbrt_LD ceil_LD
83             copysign_LD cosh_LD cos_LD erf_LD erfc_LD exp_LD expm1_LD finite_LD fabs_LD
84             fdim_LD floor_LD fma_LD fmax_LD fmin_LD fmod_LD hypot_LD isinf_LD
85             ilogb_LD isnan_LD ldexp_LD lgamma_LD log_LD log10_LD
86             log2_LD log1p_LD modf_LD nearbyint_LD nextafter_LD
87             pow_LD remainder_LD rint_LD round_LD scalbln_LD scalbn_LD signbit_LD
88             sincos_LD sinh_LD sin_LD sqrt_LD tan_LD tanh_LD tgamma_LD trunc_LD
89             );
90              
91             %Math::LongDouble::EXPORT_TAGS = (all => [qw(
92             InfLD NaNLD ZeroLD UnityLD is_NaNLD is_InfLD is_ZeroLD STRtoLD LDtoSTR NVtoLD UVtoLD IVtoLD
93             LDtoNV LDtoLD cmp_NV
94             ld_set_prec ld_get_prec LDtoSTRP
95             LD_DBL_DIG LD_LDBL_DIG LD_DBL_MANT_DIG LD_LDBL_MANT_DIG
96              
97             LD_DBL_MIN_EXP LD_DBL_MAX_EXP LD_DBL_MIN_10_EXP LD_DBL_MAX_10_EXP
98             LD_DBL_MAX LD_DBL_MIN LD_DBL_EPSILON LD_DBL_DENORM_MIN
99              
100             LD_LDBL_MIN_EXP LD_LDBL_MAX_EXP LD_LDBL_MIN_10_EXP LD_LDBL_MAX_10_EXP
101             LD_LDBL_MAX LD_LDBL_MIN LD_LDBL_EPSILON LD_LDBL_DENORM_MIN
102              
103             M_El M_LOG2El M_LOG10El M_LN2l M_LN10l M_PIl M_PI_2l M_PI_4l
104             M_1_PIl M_2_PIl M_2_SQRTPIl M_SQRT2l M_SQRT1_2l
105              
106             ld_max_orig_len ld_min_inter_prec ld_min_inter_base ld_max_orig_base ld_bytes
107              
108             llrint_LD llround_LD lrint_LD lround_LD frexp_LD nan_LD remquo_LD
109             acos_LD acosh_LD asin_LD asinh_LD atan_LD atanh_LD atan2_LD cbrt_LD ceil_LD
110             copysign_LD cosh_LD cos_LD erf_LD erfc_LD exp_LD expm1_LD finite_LD fabs_LD
111             fdim_LD floor_LD fma_LD fmax_LD fmin_LD fmod_LD hypot_LD isinf_LD
112             ilogb_LD isnan_LD ldexp_LD lgamma_LD log_LD log10_LD
113             log2_LD log1p_LD modf_LD nearbyint_LD nextafter_LD
114             pow_LD remainder_LD rint_LD round_LD scalbln_LD scalbn_LD signbit_LD
115             sincos_LD sinh_LD sin_LD sqrt_LD tan_LD tanh_LD tgamma_LD trunc_LD
116             )]);
117              
118 21     21   22637 sub dl_load_flags {0} # Prevent DynaLoader from complaining and croaking
119              
120             sub _overload_string {
121              
122 0 0   0     if(is_ZeroLD($_[0])) {
123 0 0         return '-0' if is_ZeroLD($_[0]) < 0;
124 0           return '0';
125             }
126              
127 0 0         if(is_NaNLD($_[0])) {return 'NaN'}
  0            
128 0           my $inf = is_InfLD($_[0]);
129 0 0         return '-Inf' if $inf < 0;
130 0 0         return 'Inf' if $inf > 0;
131              
132 0           my @p = split /e/i, LDtoSTR($_[0]);
133 0   0       while(substr($p[0], -1, 1) eq '0' && substr($p[0], -2, 1) ne '.') {
134 0           chop $p[0];
135             }
136 0           return $p[0] . 'e' . $p[1];
137             }
138              
139             sub new {
140              
141             # This function caters for 2 possibilities:
142             # 1) that 'new' has been called OOP style - in which
143             # case there will be a maximum of 2 args
144             # 2) that 'new' has been called as a function - in
145             # which case there will be a maximum of 1 arg.
146             # If there are no args, then we just want to return a
147             # Math::LongDouble object that's a NaN.
148              
149 0 0   0     if(!@_) {return NaNLD()}
  0            
150              
151 0 0         if(@_ > 2) {die "More than 2 arguments supplied to new()"}
  0            
152              
153             # If 'new' has been called OOP style, the first arg is the string
154             # "Math::LongDouble" which we don't need - so let's remove it. However,
155             # if the first arg is a Math::LongDouble object (which is a possibility),
156             # then we'll get a fatal error when we check it for equivalence to
157             # the string "Math::LongDouble". So we first need to check that it's
158             # not an object - which we'll do by using the ref() function:
159 0 0 0       if(!ref($_[0]) && $_[0] eq "Math::LongDouble") {
160 0           shift;
161 0 0         if(!@_) {return NaNLD()}
  0            
162             }
163              
164 0 0         if(@_ > 1) {die "Too many arguments supplied to new() - expected no more than 1"}
  0            
165              
166 0           my $arg = shift;
167 0           my $type = _itsa($arg);
168              
169 0 0         return UVtoLD ($arg) if $type == 1; # UV
170 0 0         return IVtoLD ($arg) if $type == 2; # IV
171 0 0         return NVtoLD ($arg) if $type == 3; # NV
172 0 0         return STRtoLD($arg) if $type == 4; # PV
173 0 0         return LDtoLD ($arg) if $type == 96; # Math::LongDouble object
174              
175 0           die "Bad argument given to new()";
176             }
177              
178 0     0     sub LD_DBL_DIG {return _DBL_DIG()}
179 0     0     sub LD_DBL_MANT_DIG {return _DBL_MANT_DIG()}
180 0     0     sub LD_DBL_MAX {return _DBL_MAX()}
181 0     0     sub LD_DBL_MIN {return _DBL_MIN()}
182 0     0     sub LD_DBL_EPSILON {return _DBL_EPSILON()}
183 0     0     sub LD_DBL_DENORM_MIN {return _DBL_DENORM_MIN()}
184 0     0     sub LD_DBL_MIN_EXP {return _DBL_MIN_EXP()}
185 0     0     sub LD_DBL_MAX_EXP {return _DBL_MAX_EXP()}
186 0     0     sub LD_DBL_MIN_10_EXP {return _DBL_MIN_10_EXP()}
187 0     0     sub LD_DBL_MAX_10_EXP {return _DBL_MAX_10_EXP()}
188              
189 0     0     sub LD_LDBL_DIG {return _LDBL_DIG()}
190 0     0     sub LD_LDBL_MANT_DIG {return _LDBL_MANT_DIG()}
191 0     0     sub LD_LDBL_MAX {return _LDBL_MAX()}
192 0     0     sub LD_LDBL_MIN {return _LDBL_MIN()}
193 0     0     sub LD_LDBL_EPSILON {return _LDBL_EPSILON()}
194 0     0     sub LD_LDBL_DENORM_MIN {return _LDBL_DENORM_MIN()}
195 0     0     sub LD_LDBL_MIN_EXP {return _LDBL_MIN_EXP()}
196 0     0     sub LD_LDBL_MAX_EXP {return _LDBL_MAX_EXP()}
197 0     0     sub LD_LDBL_MIN_10_EXP {return _LDBL_MIN_10_EXP()}
198 0     0     sub LD_LDBL_MAX_10_EXP {return _LDBL_MAX_10_EXP()}
199              
200 0     0     sub M_El {return _M_El()}
201 0     0     sub M_LOG2El {return _M_LOG2El()}
202 0     0     sub M_LOG10El {return _M_LOG10El()}
203 0     0     sub M_LN2l {return _M_LN2l()}
204 0     0     sub M_LN10l {return _M_LN10l()}
205 0     0     sub M_PIl {return _M_PIl()}
206 0     0     sub M_PI_2l {return _M_PI_2l()}
207 0     0     sub M_PI_4l {return _M_PI_4l()}
208 0     0     sub M_1_PIl {return _M_1_PIl()}
209 0     0     sub M_2_PIl {return _M_2_PIl()}
210 0     0     sub M_2_SQRTPIl {return _M_2_SQRTPIl()}
211 0     0     sub M_SQRT2l {return _M_SQRT2l()}
212 0     0     sub M_SQRT1_2l {return _M_SQRT1_2l()}
213              
214              
215             sub ld_min_inter_prec {
216 0 0   0     die "Wrong number of args to minimum_intermediate_prec()" if @_ != 3;
217 0           my $orig_base = shift;
218 0           my $orig_length = shift;
219 0           my $to_base = shift;
220 0           return ceil(1 + ($orig_length * log($orig_base) / log($to_base)));
221             }
222              
223             sub ld_min_inter_base {
224 0 0   0     die "Wrong number of args to minimum_intermediate_base()" if @_ != 3;
225 0           my $orig_base = shift;
226 0           my $orig_length = shift;
227 0           my $to_prec = shift;
228 0           return ceil(exp($orig_length * log($orig_base) / ($to_prec - 1)));
229             }
230              
231             sub ld_max_orig_len {
232 0 0   0     die "Wrong number of args to maximum_orig_length()" if @_ != 3;
233 0           my $orig_base = shift;
234 0           my $to_base = shift;
235 0           my $to_prec = shift;
236 0           return floor(1 / (log($orig_base) / log($to_base) / ($to_prec - 1)));
237             }
238              
239             sub ld_max_orig_base {
240 0 0   0     die "Wrong number of args to maximum_orig_base()" if @_ != 3;
241 0           my $orig_length = shift;
242 0           my $to_base = shift;
243 0           my $to_prec = shift;
244 0           return floor(exp(1 / ($orig_length / log($to_base) / ($to_prec -1))));
245             }
246              
247             sub ld_bytes {
248 0     0     my @ret = _ld_bytes($_[0]);
249 0           return join '', @ret;
250             }
251              
252             1;
253              
254             __END__