line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Math::Trig::Units; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
require Exporter; |
4
|
1
|
|
|
1
|
|
6306
|
use Carp; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
73
|
|
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
5
|
use vars qw( @ISA @EXPORT_OK $VERSION $UNITS $ZERO $pi $inf ); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
207
|
|
7
|
|
|
|
|
|
|
$VERSION = '0.03'; |
8
|
|
|
|
|
|
|
@ISA=qw(Exporter); |
9
|
|
|
|
|
|
|
@EXPORT_OK=qw( |
10
|
|
|
|
|
|
|
dsin asin |
11
|
|
|
|
|
|
|
dcos acos |
12
|
|
|
|
|
|
|
tan atan |
13
|
|
|
|
|
|
|
sec asec |
14
|
|
|
|
|
|
|
csc acsc |
15
|
|
|
|
|
|
|
cot acot |
16
|
|
|
|
|
|
|
sinh asinh |
17
|
|
|
|
|
|
|
cosh acosh |
18
|
|
|
|
|
|
|
tanh atanh |
19
|
|
|
|
|
|
|
sech asech |
20
|
|
|
|
|
|
|
csch acsch |
21
|
|
|
|
|
|
|
coth acoth |
22
|
|
|
|
|
|
|
deg_to_rad rad_to_deg |
23
|
|
|
|
|
|
|
grad_to_rad rad_to_grad |
24
|
|
|
|
|
|
|
deg_to_grad grad_to_deg |
25
|
|
|
|
|
|
|
units |
26
|
|
|
|
|
|
|
); |
27
|
|
|
|
|
|
|
|
28
|
1
|
|
|
1
|
|
2
|
BEGIN { $pi = atan2(1,1)*4; |
29
|
1
|
|
|
|
|
6
|
$inf = exp(1000000); |
30
|
1
|
|
|
|
|
1587
|
$UNITS = 'radians'; |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
|
33
|
70
|
|
|
70
|
0
|
76
|
sub deg_to_rad { my $x=$_[0]; ($x/180) * $pi } |
|
70
|
|
|
|
|
145
|
|
34
|
63
|
|
|
63
|
0
|
73
|
sub rad_to_deg { my $x=$_[0]; ($x/$pi) * 180 } |
|
63
|
|
|
|
|
260
|
|
35
|
70
|
|
|
70
|
0
|
81
|
sub grad_to_rad { my $x=$_[0]; ($x/200) * $pi } |
|
70
|
|
|
|
|
150
|
|
36
|
63
|
|
|
63
|
0
|
71
|
sub rad_to_grad { my $x=$_[0]; ($x/$pi) * 200 } |
|
63
|
|
|
|
|
222
|
|
37
|
0
|
|
|
0
|
0
|
0
|
sub deg_to_grad { my $x=$_[0]; $x/0.9 } |
|
0
|
|
|
|
|
0
|
|
38
|
0
|
|
|
0
|
0
|
0
|
sub grad_to_deg { my $x=$_[0]; $x*0.9 } |
|
0
|
|
|
|
|
0
|
|
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
sub units_to_rad { |
41
|
210
|
100
|
|
210
|
0
|
1983
|
return $UNITS =~ /gradian/i ? grad_to_rad($_[0]) : |
|
|
100
|
|
|
|
|
|
42
|
|
|
|
|
|
|
$UNITS =~ /radian/i ? $_[0] : |
43
|
|
|
|
|
|
|
deg_to_rad($_[0]); |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
sub rad_to_units { |
47
|
189
|
100
|
|
189
|
0
|
802
|
return $UNITS =~ /gradian/i ? rad_to_grad($_[0]) : |
|
|
100
|
|
|
|
|
|
48
|
|
|
|
|
|
|
$UNITS =~ /radian/i ? $_[0] : |
49
|
|
|
|
|
|
|
rad_to_deg($_[0]); |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
sub units { |
53
|
3
|
50
|
|
3
|
1
|
200
|
$UNITS = $_[0] if $_[0]; |
54
|
3
|
50
|
|
|
|
38
|
confess( "Don't know how to do $_[0] units!") unless $UNITS =~ m/degree|gradian|radian/i; |
55
|
3
|
|
|
|
|
6
|
return $UNITS; |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
15
|
|
|
15
|
1
|
552
|
sub dsin { my $x=$_[0]; $x=units_to_rad($x); return sin($x) } |
|
15
|
|
|
|
|
25
|
|
|
15
|
|
|
|
|
55
|
|
59
|
|
|
|
|
|
|
|
60
|
15
|
|
|
15
|
1
|
711
|
sub dcos { my $x=$_[0]; $x=units_to_rad($x); return cos($x) } |
|
15
|
|
|
|
|
26
|
|
|
15
|
|
|
|
|
100
|
|
61
|
|
|
|
|
|
|
|
62
|
15
|
50
|
|
15
|
1
|
711
|
sub tan { my $x=$_[0]; $x=units_to_rad($x); return cos($x)==0 ? $inf : sin($x)/cos($x) } |
|
15
|
|
|
|
|
24
|
|
|
15
|
|
|
|
|
60
|
|
63
|
|
|
|
|
|
|
|
64
|
15
|
50
|
|
15
|
1
|
879
|
sub sec { my $x=$_[0]; $x=units_to_rad($x); return cos($x)==0 ? $inf : 1/cos($x) } |
|
15
|
|
|
|
|
25
|
|
|
15
|
|
|
|
|
62
|
|
65
|
|
|
|
|
|
|
|
66
|
15
|
100
|
|
15
|
1
|
702
|
sub csc { my $x=$_[0]; $x=units_to_rad($x); return sin($x)==0 ? $inf : 1/sin($x) } |
|
15
|
|
|
|
|
25
|
|
|
15
|
|
|
|
|
66
|
|
67
|
|
|
|
|
|
|
|
68
|
15
|
100
|
|
15
|
1
|
780
|
sub cot { my $x=$_[0]; $x=units_to_rad($x); return sin($x)==0 ? $inf : cos($x)/sin($x) } |
|
15
|
|
|
|
|
25
|
|
|
15
|
|
|
|
|
64
|
|
69
|
|
|
|
|
|
|
|
70
|
30
|
50
|
33
|
30
|
1
|
33
|
sub asin { my $x=$_[0]; return ($x<-1 or $x>1) ? undef : rad_to_units( atan2($x,sqrt(1-$x*$x)) ); } |
|
30
|
|
|
|
|
199
|
|
71
|
|
|
|
|
|
|
|
72
|
30
|
50
|
33
|
30
|
1
|
33
|
sub acos { my $x=$_[0]; return ($x<-1 or $x>1) ? undef : rad_to_units( atan2(sqrt(1-$x*$x),$x) ); } |
|
30
|
|
|
|
|
176
|
|
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
sub atan { |
75
|
30
|
50
|
|
30
|
1
|
183
|
return ($_[0]==0) ? 0 : |
|
|
100
|
|
|
|
|
|
76
|
|
|
|
|
|
|
($_[0]>0) ? rad_to_units( atan2(sqrt(1+$_[0]*$_[0]),sqrt(1+1/($_[0]*$_[0]))) ) : |
77
|
|
|
|
|
|
|
rad_to_units($pi) - rad_to_units( atan2(sqrt(1+$_[0]*$_[0]),sqrt(1+1/($_[0]*$_[0]))) ); |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
|
80
|
15
|
50
|
33
|
15
|
1
|
145
|
sub asec { return ( $_[0]==0 or ($_[0]>-1 and $_[0]<1) ) ? undef : acos(1/$_[0]); } |
81
|
|
|
|
|
|
|
|
82
|
15
|
50
|
33
|
15
|
1
|
176
|
sub acsc { return ( $_[0]==0 or ($_[0]>-1 and $_[0]<1) ) ? undef : asin(1/$_[0]); } |
83
|
|
|
|
|
|
|
|
84
|
15
|
50
|
|
15
|
1
|
44
|
sub acot { return ($_[0]==0) ? rad_to_units($pi/2) : atan(1/$_[0]) } |
85
|
|
|
|
|
|
|
|
86
|
15
|
|
|
15
|
1
|
736
|
sub sinh { my $x=$_[0]; $x=units_to_rad($x); return (exp($x)-exp(-$x))/2; } |
|
15
|
|
|
|
|
23
|
|
|
15
|
|
|
|
|
63
|
|
87
|
|
|
|
|
|
|
|
88
|
15
|
|
|
15
|
1
|
784
|
sub cosh { my $x=$_[0]; $x=units_to_rad($x); return (exp($x)+exp(-$x))/2; } |
|
15
|
|
|
|
|
25
|
|
|
15
|
|
|
|
|
103
|
|
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
sub tanh { |
91
|
15
|
|
|
15
|
1
|
695
|
my($ep,$em) = (exp(units_to_rad($_[0])),exp(-units_to_rad($_[0]))); |
92
|
15
|
50
|
|
|
|
96
|
return ($ep==$inf) ? 1 : |
|
|
50
|
|
|
|
|
|
93
|
|
|
|
|
|
|
($em==$inf) ? -1 : ($ep-$em)/($ep+$em); |
94
|
|
|
|
|
|
|
} |
95
|
|
|
|
|
|
|
|
96
|
15
|
|
|
15
|
1
|
659
|
sub sech { my $x=$_[0]; $x=units_to_rad($x); return 2/(exp($x)+exp(-$x)); } |
|
15
|
|
|
|
|
24
|
|
|
15
|
|
|
|
|
44
|
|
97
|
|
|
|
|
|
|
|
98
|
15
|
100
|
|
15
|
1
|
797
|
sub csch { my $x=$_[0]; $x=units_to_rad($x); return ($x==0) ? $inf : 2/(exp($x)-exp(-$x)); } |
|
15
|
|
|
|
|
25
|
|
|
15
|
|
|
|
|
91
|
|
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
sub coth { |
101
|
15
|
|
|
15
|
1
|
776
|
my $x=units_to_rad($_[0]); |
102
|
15
|
|
|
|
|
30
|
my($ep,$em) = (exp($x),exp(-$x)); |
103
|
15
|
50
|
|
|
|
90
|
return ($x==0) ? $inf : |
|
|
50
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
104
|
|
|
|
|
|
|
($ep == $inf) ? 1 : |
105
|
|
|
|
|
|
|
($em == $inf) ? -1 : (exp($x)+exp(-$x))/(exp($x)-exp(-$x)); |
106
|
|
|
|
|
|
|
} |
107
|
|
|
|
|
|
|
|
108
|
90
|
|
|
90
|
1
|
301
|
sub asinh { return rad_to_units(log($_[0]+sqrt(1+$_[0]*$_[0]))); } |
109
|
|
|
|
|
|
|
|
110
|
15
|
50
|
|
15
|
1
|
53
|
sub acosh { return ($_[0]<1) ? $inf : asinh(sqrt($_[0]*$_[0]-1)); } # Returns positive value only! |
111
|
|
|
|
|
|
|
|
112
|
15
|
50
|
33
|
15
|
1
|
92
|
sub atanh { return ( $_[0]<=-1 or $_[0]>=1) ? $inf : asinh($_[0]/sqrt(1-$_[0]*$_[0])); } |
113
|
|
|
|
|
|
|
|
114
|
15
|
50
|
33
|
15
|
1
|
106
|
sub asech { return ( $_[0]<=0 or $_[0]>1 ) ? $inf : asinh(sqrt(1-$_[0]*$_[0])/$_[0]); } # Returns positive value only! |
115
|
|
|
|
|
|
|
|
116
|
15
|
50
|
|
15
|
1
|
40
|
sub acsch { return ( $_[0]==0 ) ? $inf : asinh(1/$_[0]); } |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
sub acoth { |
119
|
15
|
50
|
33
|
15
|
1
|
105
|
return ($_[0]>=-1 and $_[0]<=1) ? $inf : |
|
|
50
|
|
|
|
|
|
120
|
|
|
|
|
|
|
($_[0]<-1) ? -asinh(1/sqrt($_[0]*$_[0]-1)) : |
121
|
|
|
|
|
|
|
asinh(1/sqrt($_[0]*$_[0]-1)); |
122
|
|
|
|
|
|
|
} |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
1; |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
__END__ |