eqn 1.3.1 → 1.3.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +2 -0
- data/README.md +6 -6
- data/lib/eqn/expression.rb +0 -2
- data/lib/eqn/function.rb +17 -3
- data/lib/eqn/terminal.rb +0 -2
- data/lib/eqn/version.rb +1 -1
- data/lib/eqn.treetop +7 -3
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1719c42c8c6c2969cbc5bc1895317205b233a23b
|
4
|
+
data.tar.gz: c3917e3e216c4c5cb6738886d505bde0f2ab73b6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7bc8f654be594c43376da76c350026ffc6be2078047b334aa8d5ab3fad3b04e5d86bab77f9a7d6d9a6ea7c895eeb8dd314173260d5982132a7cfd1d288a13de1
|
7
|
+
data.tar.gz: 28202b1fa04f0ee38140bf772699b68dd2643e8f3f8506fe38f693baf294ae82533219379b87c91b117003fd33bd76f7e5ffbd996e887dee9b0d28438f49a20a
|
data/.rubocop.yml
CHANGED
data/README.md
CHANGED
@@ -70,21 +70,21 @@ For example, `if(5 > 3, 1, 2)` would evaluate to `1`.
|
|
70
70
|
|
71
71
|
**round**
|
72
72
|
|
73
|
-
Syntax: `round(number)`
|
73
|
+
Syntax: `round(number, [decimals])`
|
74
74
|
|
75
|
-
Rounds the number up if the decimal is greater than 0.5 and down otherwise (i.e. "normal" rounding).
|
75
|
+
Rounds the number up if the decimal is greater than 0.5 and down otherwise (i.e. "normal" rounding). Optionally, pass a number of decimal places to round to as a second parameter (the default is 0).
|
76
76
|
|
77
77
|
**roundup**
|
78
78
|
|
79
|
-
Syntax: `roundup(number)`
|
79
|
+
Syntax: `roundup(number, [decimals])`
|
80
80
|
|
81
|
-
Rounds the number up
|
81
|
+
Rounds the number up (i.e. ceiling function). Optionally, pass a number of decimal places to round to as a second parameter (the default is 0).
|
82
82
|
|
83
83
|
**rounddown**
|
84
84
|
|
85
|
-
Syntax: `rounddown(number)`
|
85
|
+
Syntax: `rounddown(number, [decimals])`
|
86
86
|
|
87
|
-
Rounds the number down
|
87
|
+
Rounds the number down (i.e. floor function). Optionally, pass a number of decimal places to round to as a second parameter (the default is 0).
|
88
88
|
|
89
89
|
## Development
|
90
90
|
|
data/lib/eqn/expression.rb
CHANGED
@@ -10,7 +10,6 @@ module Eqn
|
|
10
10
|
elements.empty?
|
11
11
|
end
|
12
12
|
|
13
|
-
# rubocop:disable Metrics/AbcSize
|
14
13
|
def value
|
15
14
|
if elements.count == 1
|
16
15
|
elements.shift.value
|
@@ -34,7 +33,6 @@ module Eqn
|
|
34
33
|
end
|
35
34
|
end
|
36
35
|
end
|
37
|
-
# rubocop:enable Metrics/AbcSize
|
38
36
|
|
39
37
|
class ExprGroup < Node
|
40
38
|
def left_associative?
|
data/lib/eqn/function.rb
CHANGED
@@ -16,7 +16,11 @@ module Eqn
|
|
16
16
|
def value
|
17
17
|
value = elements.shift.value
|
18
18
|
fail ZeroDivisionError if value.is_a?(Float) && (value.abs == Float::INFINITY || value.nan?)
|
19
|
-
|
19
|
+
if elements.empty?
|
20
|
+
value.round
|
21
|
+
else
|
22
|
+
value.round(elements.shift.value)
|
23
|
+
end
|
20
24
|
end
|
21
25
|
end
|
22
26
|
|
@@ -24,7 +28,12 @@ module Eqn
|
|
24
28
|
def value
|
25
29
|
value = elements.shift.value
|
26
30
|
fail ZeroDivisionError if value.is_a?(Float) && (value.abs == Float::INFINITY || value.nan?)
|
27
|
-
|
31
|
+
if elements.empty?
|
32
|
+
value.ceil
|
33
|
+
else
|
34
|
+
decimals = elements.shift.value
|
35
|
+
(value * 10**decimals).ceil.to_f / 10**decimals
|
36
|
+
end
|
28
37
|
end
|
29
38
|
end
|
30
39
|
|
@@ -32,7 +41,12 @@ module Eqn
|
|
32
41
|
def value
|
33
42
|
value = elements.shift.value
|
34
43
|
fail ZeroDivisionError if value.is_a?(Float) && (value.abs == Float::INFINITY || value.nan?)
|
35
|
-
|
44
|
+
if elements.empty?
|
45
|
+
value.floor
|
46
|
+
else
|
47
|
+
decimals = elements.shift.value
|
48
|
+
(value * 10**decimals).floor.to_f / 10**decimals
|
49
|
+
end
|
36
50
|
end
|
37
51
|
end
|
38
52
|
end
|
data/lib/eqn/terminal.rb
CHANGED
@@ -3,7 +3,6 @@ module Eqn
|
|
3
3
|
class Node < Treetop::Runtime::SyntaxNode; end
|
4
4
|
|
5
5
|
class Variable < Node
|
6
|
-
# rubocop:disable Metrics/AbcSize
|
7
6
|
def value
|
8
7
|
unless Eqn::Calculator.class_variable_get(:@@vars).key? text_value.intern
|
9
8
|
fail NoVariableValueError, "No value given for: #{text_value}"
|
@@ -13,7 +12,6 @@ module Eqn
|
|
13
12
|
end
|
14
13
|
Eqn::Calculator.class_variable_get(:@@vars)[text_value.intern]
|
15
14
|
end
|
16
|
-
# rubocop:enable Metrics/AbcSize
|
17
15
|
end
|
18
16
|
|
19
17
|
class Digits < Node
|
data/lib/eqn/version.rb
CHANGED
data/lib/eqn.treetop
CHANGED
@@ -44,15 +44,19 @@ grammar Eqn
|
|
44
44
|
end
|
45
45
|
|
46
46
|
rule round_func
|
47
|
-
'round' space?
|
47
|
+
'round' space? '(' expression round_group? ')' <Eqn::Function::Round>
|
48
48
|
end
|
49
49
|
|
50
50
|
rule roundup_func
|
51
|
-
'roundup' space?
|
51
|
+
'roundup' space? '(' expression round_group? ')' <Eqn::Function::RoundUp>
|
52
52
|
end
|
53
53
|
|
54
54
|
rule rounddown_func
|
55
|
-
'rounddown' space?
|
55
|
+
'rounddown' space? '(' expression round_group? ')' <Eqn::Function::RoundDown>
|
56
|
+
end
|
57
|
+
|
58
|
+
rule round_group
|
59
|
+
',' expression <Eqn::Expression>
|
56
60
|
end
|
57
61
|
|
58
62
|
rule group
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: eqn
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.3.
|
4
|
+
version: 1.3.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Zach Schneider
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-10-
|
11
|
+
date: 2015-10-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: treetop
|