eqn 1.1.0 → 1.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +4 -0
- data/lib/eqn.treetop +9 -1
- data/lib/eqn/calculator.rb +1 -1
- data/lib/eqn/number.rb +15 -8
- data/lib/eqn/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 08c722b548df16e9f686ca109df362c10592c8a0
|
4
|
+
data.tar.gz: aedb663d5c308aaf018bab79028432e0538883be
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f8c56e988905d9860e879241e9ce231db2d1ba82a68e38a317d09b575ecc9a53e228288b88e1b0a448ff4bb5cfeac1b4c6bc429e7e4b730d9600f5c564d2a90b
|
7
|
+
data.tar.gz: 24b4da1f8663c8cbb6c12246ecbe82eb78a477ab093370c81a37605492b50a0b783fe13df6ca3a892de65fb016ae2ad56ca4a8eeeeb8b4ccaaee9861582f8a6d
|
data/README.md
CHANGED
@@ -75,6 +75,10 @@ After checking out the repo, run `bin/setup` to install dependencies. Then, run
|
|
75
75
|
|
76
76
|
The gem uses rspec for testing; run `rspec` from the application root to execute the tests.
|
77
77
|
|
78
|
+
## Authorship
|
79
|
+
|
80
|
+
Written by Zach Schneider for [Aha!, the world's #1 product roadmap software](http://www.aha.io/)
|
81
|
+
|
78
82
|
## Contributing
|
79
83
|
|
80
84
|
1. Fork it ( https://github.com/schneidmaster/eqn/fork )
|
data/lib/eqn.treetop
CHANGED
@@ -64,7 +64,11 @@ grammar Eqn
|
|
64
64
|
end
|
65
65
|
|
66
66
|
rule signed_float
|
67
|
-
sign? space? digits
|
67
|
+
sign? space? (float / digits) <Eqn::Number::SignedNumber>
|
68
|
+
end
|
69
|
+
|
70
|
+
rule float
|
71
|
+
digits? decimal <Eqn::Number::Float>
|
68
72
|
end
|
69
73
|
|
70
74
|
rule decimal
|
@@ -99,6 +103,10 @@ grammar Eqn
|
|
99
103
|
/ '!=' <Eqn::Terminal::CompOp::Neq>
|
100
104
|
end
|
101
105
|
|
106
|
+
rule dot
|
107
|
+
'.' <Eqn::Terminal::Dot>
|
108
|
+
end
|
109
|
+
|
102
110
|
rule exp
|
103
111
|
'e' / 'E'
|
104
112
|
end
|
data/lib/eqn/calculator.rb
CHANGED
@@ -3,7 +3,7 @@ module Eqn
|
|
3
3
|
class << self
|
4
4
|
def calc(data)
|
5
5
|
result = Parser.parse(data).value
|
6
|
-
fail ZeroDivisionError if result.is_a?(Float) && result.abs == Float::INFINITY
|
6
|
+
fail ZeroDivisionError if result.is_a?(Float) && (result.abs == Float::INFINITY || result.nan?)
|
7
7
|
result
|
8
8
|
end
|
9
9
|
|
data/lib/eqn/number.rb
CHANGED
@@ -9,27 +9,34 @@ module Eqn
|
|
9
9
|
base
|
10
10
|
end
|
11
11
|
|
12
|
-
# rubocop:disable Metrics/AbcSize
|
13
12
|
class SignedNumber < Node
|
14
13
|
def value
|
15
14
|
# Store sign if any.
|
16
15
|
sign_negative = elements.shift.negative? if elements.first.is_a? Terminal::Sign
|
17
16
|
|
18
|
-
#
|
19
|
-
|
20
|
-
|
21
|
-
# Handle decimal.
|
22
|
-
base += elements.shift.value unless elements.empty?
|
17
|
+
# Evaluate float.
|
18
|
+
value = elements.shift.value
|
23
19
|
|
24
20
|
# Apply sign if any.
|
25
21
|
if sign_negative
|
26
|
-
-
|
22
|
+
-value
|
27
23
|
else
|
28
|
-
|
24
|
+
value
|
29
25
|
end
|
30
26
|
end
|
31
27
|
end
|
32
28
|
|
29
|
+
class Float < Node
|
30
|
+
def value
|
31
|
+
base = elements.shift.value
|
32
|
+
|
33
|
+
# Add any decimal.
|
34
|
+
base += elements.shift.value unless elements.empty?
|
35
|
+
|
36
|
+
base
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
33
40
|
class Decimal < Node
|
34
41
|
def value
|
35
42
|
elements.shift.dec_value
|
data/lib/eqn/version.rb
CHANGED