File Coverage

lib/POSIX/1003/Math.pm
Criterion Covered Total %
statement 19 37 51.3
branch 0 2 0.0
condition n/a
subroutine 7 24 29.1
pod 17 17 100.0
total 43 80 53.7


line stmt bran cond sub pod time code
1             # Copyrights 2011-2015 by [Mark Overmeer].
2             # For other contributors see ChangeLog.
3             # See the manual pages for details on the licensing terms.
4             # Pod stripped from pm file by OODoc 2.01.
5 3     3   24957 use warnings;
  3         5  
  3         101  
6 3     3   12 use strict;
  3         4  
  3         123  
7              
8             package POSIX::1003::Math;
9 3     3   14 use vars '$VERSION';
  3         2  
  3         146  
10             $VERSION = '0.99_06';
11              
12 3     3   12 use base 'POSIX::1003::Module';
  3         3  
  3         711  
13              
14             my @constants;
15              
16             # Only from math.h. The first block are defined in POSIX.xs, the
17             # second block present in Core. The last is from string.h
18             our @IN_CORE = qw/abs exp log sqrt sin cos atan2 rand srand int/;
19              
20             my @functions = qw/
21             acos asin atan ceil cosh floor fmod frexp
22             ldexp log10 modf sinh tan tanh
23              
24             div rint pow
25             strtod strtol strtoul
26             /;
27              
28             push @functions, @IN_CORE;
29              
30             our %EXPORT_TAGS =
31             ( constants => \@constants
32             , functions => \@functions
33             , tables => [ '%math' ]
34             );
35              
36             my $math;
37             our %math;
38              
39             BEGIN {
40 3     3   85 $math = math_table;
41 3         52 push @constants, keys %$math;
42 3         19 tie %math, 'POSIX::1003::ReadOnlyTable', $math;
43             }
44              
45              
46             # the argument to be optional is important for expression priority!
47 0     0 1 0 sub acos(_) { goto &POSIX::acos }
48 0     0 1 0 sub asin(_) { goto &POSIX::asin }
49 0     0 1 0 sub atan(_) { goto &POSIX::atan }
50 0     0 1 0 sub ceil(_) { goto &POSIX::ceil }
51 0     0 1 0 sub cosh(_) { goto &POSIX::cosh }
52 2     2 1 1131 sub floor(_) { goto &POSIX::floor }
53 0     0 1 0 sub frexp(_) { goto &POSIX::frexp }
54 0     0 1 0 sub ldexp(_) { goto &POSIX::ldexp }
55 0     0 1 0 sub log10(_) { goto &POSIX::log10 }
56 0     0 1 0 sub sinh(_) { goto &POSIX::sinh }
57 0     0 1 0 sub tan(_) { goto &POSIX::tan }
58 0     0 1 0 sub tanh(_) { goto &POSIX::tanh }
59              
60 0     0 1 0 sub modf($$) { goto &POSIX::modf }
61 0     0 1 0 sub fmod($$) { goto &POSIX::fmod }
62              
63             # All provided by POSIX.xs
64              
65              
66 0     0 1 0 sub div($$) { ( int($_[0]/$_[1]), ($_[0] % $_[1]) ) }
67              
68              
69 0 0   0 1 0 sub rint(;$) { my $v = @_ ? shift : $_; int($v + 0.5) }
  0         0  
70              
71              
72 0     0 1 0 sub pow($$) { $_[0] ** $_[1] }
73              
74              
75             #------------------------------
76              
77              
78             sub _create_constant($)
79 92     92   112 { my ($class, $name) = @_;
80 92         117 my $val = $math->{$name};
81 92     0   567 sub () {$val};
  0            
82             }
83              
84             1;