line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Number::Equation; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
135154
|
use 5.006; |
|
2
|
|
|
|
|
15
|
|
4
|
2
|
|
|
2
|
|
9
|
use strict; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
46
|
|
5
|
2
|
|
|
2
|
|
18
|
use warnings; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
358
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
our $VERSION = '0.02'; |
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
|
|
|
|
|
|
|
'""' => sub { |
19
|
2
|
|
|
2
|
|
3
|
my $num = $_[0][0]; |
20
|
2
|
50
|
|
|
|
5
|
return $num unless $precision; |
21
|
2
|
50
|
|
|
|
16
|
return $num >= 0 |
22
|
|
|
|
|
|
|
? $precision * int(($num + ($offset * $precision)) / $precision) |
23
|
|
|
|
|
|
|
: $precision * POSIX::ceil(($num - $offset * $precision) / $precision); |
24
|
|
|
|
|
|
|
}, |
25
|
2
|
|
|
2
|
|
3198
|
fallback => 1; |
|
2
|
|
|
|
|
1852
|
|
|
2
|
|
|
|
|
27
|
|
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
sub new { |
28
|
1
|
|
|
1
|
0
|
73
|
my $self = bless [ $_[1], [$_[1]] ], $_[0]; |
29
|
1
|
50
|
|
|
|
4
|
$precision = $_[2] if $_[2]; |
30
|
1
|
50
|
|
|
|
5
|
$offset = $_[3] if $_[3]; |
31
|
1
|
|
|
|
|
2
|
$self; |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
sub add { |
35
|
1
|
|
|
1
|
0
|
4
|
push @{ $_[0][-1] }, '+', $_[1]; |
|
1
|
|
|
|
|
3
|
|
36
|
1
|
|
|
|
|
2
|
$_[0][0] += $_[1]; |
37
|
1
|
|
|
|
|
11
|
$_[0]; |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
sub mult { |
41
|
1
|
|
|
1
|
0
|
5
|
push @{ $_[0][-1] }, '*', $_[1]; |
|
1
|
|
|
|
|
3
|
|
42
|
1
|
|
|
|
|
3
|
$_[0][0] *= $_[1]; |
43
|
1
|
|
|
|
|
1
|
$_[0]; |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
sub subt { |
47
|
2
|
100
|
|
2
|
0
|
28
|
if ($_[2]) { |
48
|
1
|
|
|
|
|
2
|
splice @{ $_[0] }, 1, 0, [$_[1], '-']; |
|
1
|
|
|
|
|
4
|
|
49
|
1
|
|
|
|
|
3
|
$_[0][0] = $_[1] - $_[0][0]; |
50
|
|
|
|
|
|
|
} else { |
51
|
1
|
|
|
|
|
2
|
push @{ $_[0][-1] }, '-', $_[1]; |
|
1
|
|
|
|
|
4
|
|
52
|
1
|
|
|
|
|
4
|
$_[0][0] = $_[0][0] - $_[1]; |
53
|
|
|
|
|
|
|
} |
54
|
2
|
|
|
|
|
5
|
$_[0]; |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
sub div { |
59
|
2
|
100
|
|
2
|
0
|
9
|
if ($_[2]) { |
60
|
1
|
|
|
|
|
2
|
splice @{ $_[0] }, 1, 0, [$_[1], '/']; |
|
1
|
|
|
|
|
3
|
|
61
|
1
|
|
|
|
|
3
|
$_[0][0] = $_[1] / $_[0][0]; |
62
|
|
|
|
|
|
|
} else { |
63
|
1
|
|
|
|
|
2
|
push @{ $_[0][-1] }, '/', $_[1]; |
|
1
|
|
|
|
|
3
|
|
64
|
1
|
|
|
|
|
3
|
$_[0][0] = $_[0][0] / $_[1]; |
65
|
|
|
|
|
|
|
} |
66
|
2
|
|
|
|
|
5
|
$_[0]; |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
sub equation { |
70
|
2
|
|
|
2
|
0
|
8
|
my $query = ''; |
71
|
2
|
|
|
|
|
3
|
my $closing = 0; |
72
|
2
|
|
|
|
|
3
|
for (my $i = 1; $i <= scalar @{ $_[0] } - 1; $i++) { |
|
7
|
|
|
|
|
16
|
|
73
|
5
|
|
|
|
|
7
|
my $equation = $_[0]->[$i]; |
74
|
5
|
|
|
|
|
6
|
$query .= '(' x ((scalar @{ $equation }) / 2) . $equation->[0]; |
|
5
|
|
|
|
|
13
|
|
75
|
5
|
|
|
|
|
8
|
for (my $x = 1; $x <= scalar @{ $equation } - 1; $x++) { |
|
16
|
|
|
|
|
26
|
|
76
|
11
|
|
|
|
|
12
|
my $operator = $equation->[$x++]; |
77
|
11
|
|
|
|
|
13
|
my $val = $equation->[$x]; |
78
|
11
|
100
|
|
|
|
24
|
$query .= ' ' . $operator . ' ' . (defined $val ? ($val . ')') : do { $closing++; "" }); |
|
3
|
|
|
|
|
3
|
|
|
3
|
|
|
|
|
5
|
|
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
} |
81
|
2
|
|
|
|
|
3
|
$query .= ')' x $closing; |
82
|
2
|
50
|
|
|
|
7
|
$query .= ($precision ? ' ≈ ' : ' = ') . $_[0]; |
83
|
2
|
|
|
|
|
7
|
return $query; |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
1; # End of Number::Equation |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
__END__; |