line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Math::nSphere; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
our $VERSION = '0.01'; |
4
|
|
|
|
|
|
|
|
5
|
1
|
|
|
1
|
|
624
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
30
|
|
6
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
22
|
|
7
|
1
|
|
|
1
|
|
5
|
use Carp; |
|
1
|
|
|
|
|
5
|
|
|
1
|
|
|
|
|
84
|
|
8
|
|
|
|
|
|
|
|
9
|
1
|
|
|
1
|
|
5
|
use Exporter qw(import); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
392
|
|
10
|
|
|
|
|
|
|
our @EXPORT_OK = qw(nsphere_surface nsphere_volumen); |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
my $PI = 3.14159265358979323846264338327950288419716939937510; |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
my @S = ( 0 , 2 * $PI , 4 * $PI ); |
15
|
|
|
|
|
|
|
my @V = ( 0 , 2 , $PI , 4 / 3 * $PI ); |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
sub nsphere_surface { |
18
|
30
|
|
|
30
|
1
|
6983
|
my ($n, $r) = @_; |
19
|
30
|
|
|
|
|
39
|
my $S = $S[$n]; |
20
|
30
|
100
|
|
|
|
53
|
unless (defined $S) { |
21
|
2
|
|
|
|
|
3
|
$n = int $n; |
22
|
2
|
50
|
|
|
|
6
|
$n >= 0 or croak "index out of range"; |
23
|
2
|
|
|
|
|
1
|
my $i = $n; |
24
|
2
|
|
|
|
|
25
|
$i -= 2 until defined $S[$i]; |
25
|
2
|
|
|
|
|
3
|
$S = $S[$i]; |
26
|
2
|
|
|
|
|
6
|
while ($i < $n) { |
27
|
29
|
|
|
|
|
25
|
$i += 2; |
28
|
29
|
|
|
|
|
53
|
$S[$i] = $S = 2 * $PI * $S / ($i - 1); |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
}; |
31
|
30
|
50
|
|
|
|
100
|
return $S unless defined $r; |
32
|
0
|
|
|
|
|
0
|
$r ** $n * $S; |
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
sub nsphere_volumen { |
36
|
39
|
|
|
39
|
1
|
56
|
my ($n, $r) = @_; |
37
|
39
|
|
|
|
|
45
|
my $V = $V[$n]; |
38
|
39
|
100
|
|
|
|
72
|
unless (defined $V) { |
39
|
7
|
|
|
|
|
11
|
$n = int $n; |
40
|
7
|
50
|
|
|
|
13
|
$n >= 0 or croak "index out of range"; |
41
|
7
|
|
|
|
|
10
|
my $i = $n; |
42
|
7
|
|
|
|
|
37
|
$i -= 2 until defined $V[$i]; |
43
|
7
|
|
|
|
|
9
|
$V = $V[$i]; |
44
|
7
|
|
|
|
|
14
|
while ($i < $n) { |
45
|
27
|
|
|
|
|
22
|
$i += 2; |
46
|
27
|
|
|
|
|
62
|
$V[$i] = $V = 2 * $PI * $V / $i; |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
}; |
49
|
39
|
50
|
|
|
|
207
|
return $V unless defined $r; |
50
|
0
|
|
|
|
|
|
$r ** ($n + 1) * $V; |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
1; |
54
|
|
|
|
|
|
|
__END__ |