line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Number::Equation; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
132159
|
use 5.006; |
|
2
|
|
|
|
|
15
|
|
4
|
2
|
|
|
2
|
|
13
|
use strict; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
66
|
|
5
|
2
|
|
|
2
|
|
12
|
use warnings; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
447
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
our $VERSION = '0.03'; |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
our $offset = 0.5555555; |
10
|
|
|
|
|
|
|
our $precision = 0; |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
# TODO |
13
|
|
|
|
|
|
|
use overload |
14
|
|
|
|
|
|
|
'+' => \&add, |
15
|
|
|
|
|
|
|
'-' => \&subt, |
16
|
|
|
|
|
|
|
'/' => \&div, |
17
|
|
|
|
|
|
|
'*' => \&mult, |
18
|
|
|
|
|
|
|
'%' => \&mod, |
19
|
|
|
|
|
|
|
'**' => \&exp, |
20
|
|
|
|
|
|
|
'""' => sub { |
21
|
6
|
|
|
6
|
|
425
|
my $num = $_[0][0]; |
22
|
6
|
100
|
|
|
|
33
|
return $num unless $precision; |
23
|
2
|
50
|
|
|
|
22
|
return $num >= 0 |
24
|
|
|
|
|
|
|
? $precision * int(($num + ($offset * $precision)) / $precision) |
25
|
|
|
|
|
|
|
: $precision * POSIX::ceil(($num - $offset * $precision) / $precision); |
26
|
|
|
|
|
|
|
}, |
27
|
2
|
|
|
2
|
|
2299
|
fallback => 1; |
|
2
|
|
|
|
|
2048
|
|
|
2
|
|
|
|
|
25
|
|
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
sub new { |
30
|
3
|
|
|
3
|
0
|
103
|
my $self = bless [ $_[1], [$_[1]] ], $_[0]; |
31
|
3
|
50
|
|
|
|
11
|
$precision = $_[2] if defined $_[2]; |
32
|
3
|
50
|
|
|
|
9
|
$offset = $_[3] if $_[3]; |
33
|
3
|
|
|
|
|
11
|
$self; |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
sub add { |
37
|
1
|
|
|
1
|
0
|
5
|
push @{ $_[0][-1] }, '+', $_[1]; |
|
1
|
|
|
|
|
4
|
|
38
|
1
|
|
|
|
|
3
|
$_[0][0] += $_[1]; |
39
|
1
|
|
|
|
|
14
|
$_[0]; |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
sub mult { |
43
|
1
|
|
|
1
|
0
|
7
|
push @{ $_[0][-1] }, '*', $_[1]; |
|
1
|
|
|
|
|
4
|
|
44
|
1
|
|
|
|
|
5
|
$_[0][0] *= $_[1]; |
45
|
1
|
|
|
|
|
3
|
$_[0]; |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
sub subt { |
49
|
2
|
100
|
|
2
|
0
|
41
|
if ($_[2]) { |
50
|
1
|
|
|
|
|
3
|
splice @{ $_[0] }, 1, 0, [$_[1], '-']; |
|
1
|
|
|
|
|
5
|
|
51
|
1
|
|
|
|
|
4
|
$_[0][0] = $_[1] - $_[0][0]; |
52
|
|
|
|
|
|
|
} else { |
53
|
1
|
|
|
|
|
2
|
push @{ $_[0][-1] }, '-', $_[1]; |
|
1
|
|
|
|
|
5
|
|
54
|
1
|
|
|
|
|
38
|
$_[0][0] = $_[0][0] - $_[1]; |
55
|
|
|
|
|
|
|
} |
56
|
2
|
|
|
|
|
6
|
$_[0]; |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
sub div { |
61
|
2
|
100
|
|
2
|
0
|
15
|
if ($_[2]) { |
62
|
1
|
|
|
|
|
2
|
splice @{ $_[0] }, 1, 0, [$_[1], '/']; |
|
1
|
|
|
|
|
4
|
|
63
|
1
|
|
|
|
|
3
|
$_[0][0] = $_[1] / $_[0][0]; |
64
|
|
|
|
|
|
|
} else { |
65
|
1
|
|
|
|
|
3
|
push @{ $_[0][-1] }, '/', $_[1]; |
|
1
|
|
|
|
|
4
|
|
66
|
1
|
|
|
|
|
6
|
$_[0][0] = $_[0][0] / $_[1]; |
67
|
|
|
|
|
|
|
} |
68
|
2
|
|
|
|
|
19
|
$_[0]; |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
sub mod { |
72
|
1
|
50
|
|
1
|
0
|
8
|
if ($_[2]) { |
73
|
0
|
|
|
|
|
0
|
splice @{ $_[0] }, 1, 0, [$_[1], '%']; |
|
0
|
|
|
|
|
0
|
|
74
|
0
|
|
|
|
|
0
|
$_[0][0] = $_[1] % $_[0][0]; |
75
|
|
|
|
|
|
|
} else { |
76
|
1
|
|
|
|
|
2
|
push @{ $_[0][-1] }, '%', $_[1]; |
|
1
|
|
|
|
|
6
|
|
77
|
1
|
|
|
|
|
4
|
$_[0][0] = $_[0][0] % $_[1]; |
78
|
|
|
|
|
|
|
} |
79
|
1
|
|
|
|
|
2
|
$_[0]; |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
sub exp { |
83
|
1
|
50
|
|
1
|
0
|
9
|
if ($_[2]) { |
84
|
0
|
|
|
|
|
0
|
splice @{ $_[0] }, 1, 0, [$_[1], '**']; |
|
0
|
|
|
|
|
0
|
|
85
|
0
|
|
|
|
|
0
|
$_[0][0] = $_[1] ** $_[0][0]; |
86
|
|
|
|
|
|
|
} else { |
87
|
1
|
|
|
|
|
2
|
push @{ $_[0][-1] }, '**', $_[1]; |
|
1
|
|
|
|
|
4
|
|
88
|
1
|
|
|
|
|
4
|
$_[0][0] = $_[0][0] ** $_[1]; |
89
|
|
|
|
|
|
|
} |
90
|
1
|
|
|
|
|
3
|
$_[0]; |
91
|
|
|
|
|
|
|
} |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
sub equation { |
94
|
4
|
|
|
4
|
0
|
603
|
my $query = ''; |
95
|
4
|
|
|
|
|
7
|
my $closing = 0; |
96
|
4
|
|
|
|
|
7
|
for (my $i = 1; $i <= scalar @{ $_[0] } - 1; $i++) { |
|
11
|
|
|
|
|
26
|
|
97
|
7
|
|
|
|
|
12
|
my $equation = $_[0]->[$i]; |
98
|
7
|
|
|
|
|
9
|
$query .= '(' x ((scalar @{ $equation }) / 2) . $equation->[0]; |
|
7
|
|
|
|
|
24
|
|
99
|
7
|
|
|
|
|
13
|
for (my $x = 1; $x <= scalar @{ $equation } - 1; $x++) { |
|
20
|
|
|
|
|
40
|
|
100
|
13
|
|
|
|
|
19
|
my $operator = $equation->[$x++]; |
101
|
13
|
|
|
|
|
19
|
my $val = $equation->[$x]; |
102
|
13
|
100
|
|
|
|
33
|
$query .= ' ' . $operator . ' ' . (defined $val ? ($val . ')') : do { $closing++; "" }); |
|
3
|
|
|
|
|
4
|
|
|
3
|
|
|
|
|
7
|
|
103
|
|
|
|
|
|
|
} |
104
|
|
|
|
|
|
|
} |
105
|
4
|
|
|
|
|
9
|
$query .= ')' x $closing; |
106
|
4
|
100
|
|
|
|
16
|
$query .= ($precision ? ' ≈ ' : ' = ') . $_[0]; |
107
|
4
|
|
|
|
|
22
|
return $query; |
108
|
|
|
|
|
|
|
} |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
1; # End of Number::Equation |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
__END__; |