dentaku 1.2.3 → 1.2.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5b3af0752b4a5aa4575036f593ead2f9df154721
4
- data.tar.gz: ab61cb8ebd50a48d179197724019a6f5ec167556
3
+ metadata.gz: 2b6c2a647d615b07bb92995438da601259cb87f3
4
+ data.tar.gz: 75c685525c0eb619726c0d03ded7401573eaaf33
5
5
  SHA512:
6
- metadata.gz: 58d3524e23835e1c842e35a91390c8601cb59fd5da31efdd234edb2e7551399e5b0c176f4f30cbb2f5b849f6cceab16661ae473a95b8ca32fc56913ec8f0f580
7
- data.tar.gz: 697075e3d8a11586404c83b2ea0ff685079ab0dc3b80123e87fecfc411d4913a0012573ac7ec87eca55a6205d5957723a7a0e5edcaf8bc295b2937d096ac8667
6
+ metadata.gz: 7035e118512d9c98dbcc31cb510358e8ca5fee3b98b9bb2242671a7ede8c8ae0c1e4028869367615b9c91a9ff82cece3c13e70032547ef432539c9d0b8986be1
7
+ data.tar.gz: fb40309c2d88b7036462a4acb372753350b6655a519fa165a0f534a5464a50088cd53aa908c33e59c06bb957e69305190bd33361805d6346961c8a04126a39a7
@@ -102,6 +102,10 @@ module Dentaku
102
102
  Token.new(base.category, base.value ** (exp.value * -1))
103
103
  end
104
104
 
105
+ def mul_negate(val1, _, _, val2)
106
+ Token.new(val1.category, val1.value * val2.value * -1)
107
+ end
108
+
105
109
  def percentage(token, _)
106
110
  Token.new(token.category, token.value / 100.0)
107
111
  end
data/lib/dentaku/rules.rb CHANGED
@@ -18,6 +18,7 @@ module Dentaku
18
18
  [ p(:math_neg_pow), :pow_negate ],
19
19
  [ p(:math_mod), :apply ],
20
20
  [ p(:math_mul), :apply ],
21
+ [ p(:math_neg_mul), :mul_negate ],
21
22
  [ p(:math_add), :apply ],
22
23
  [ p(:percentage), :percentage ],
23
24
  [ p(:negation), :negate ],
@@ -69,7 +70,7 @@ module Dentaku
69
70
  :comparator, :comp_gt, :comp_lt, :fopen, :open, :close, :comma,
70
71
  :non_close_plus, :non_group, :non_group_star, :arguments,
71
72
  :logical, :combinator, :if, :round, :roundup, :rounddown, :not,
72
- :anchored_minus, :math_neg_pow
73
+ :anchored_minus, :math_neg_pow, :math_neg_mul
73
74
  ].each_with_object({}) do |name, matchers|
74
75
  matchers[name] = TokenMatcher.send(name)
75
76
  end
@@ -80,6 +81,7 @@ module Dentaku
80
81
  group: pattern(:open, :non_group_star, :close),
81
82
  math_add: pattern(:numeric, :addsub, :numeric),
82
83
  math_mul: pattern(:numeric, :muldiv, :numeric),
84
+ math_neg_mul: pattern(:numeric, :muldiv, :subtract, :numeric),
83
85
  math_pow: pattern(:numeric, :pow, :numeric),
84
86
  math_neg_pow: pattern(:numeric, :pow, :subtract, :numeric),
85
87
  math_mod: pattern(:numeric, :mod, :numeric),
@@ -1,3 +1,3 @@
1
1
  module Dentaku
2
- VERSION = "1.2.3"
2
+ VERSION = "1.2.4"
3
3
  end
@@ -24,6 +24,8 @@ describe Dentaku::Calculator do
24
24
  expect(calculator.evaluate('-num + 3', :num => 2)).to eq(1)
25
25
  expect(calculator.evaluate('10 ^ 2')).to eq(100)
26
26
  expect(calculator.evaluate('0 * 10 ^ -5')).to eq(0)
27
+ expect(calculator.evaluate('3 + 0 * -3')).to eq(3)
28
+ expect(calculator.evaluate('3 + 0 / -3')).to eq(3)
27
29
  end
28
30
 
29
31
  describe 'memory' do
@@ -46,6 +46,7 @@ describe Dentaku::Evaluator do
46
46
  expect(evaluator.evaluate(token_stream(1, :subtract, :subtract, 1))).to eq(2)
47
47
  expect(evaluator.evaluate(token_stream(1, :subtract, :subtract, :subtract, 1))).to eq(0)
48
48
  expect(evaluator.evaluate(token_stream(:subtract, 1, :add, 1))).to eq(0)
49
+ expect(evaluator.evaluate(token_stream(3, :add, 0, :multiply, :subtract, 3))).to eq(3)
49
50
  end
50
51
 
51
52
  it 'evaluates a number multiplied by an exponent' do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dentaku
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.3
4
+ version: 1.2.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Solomon White
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-12-23 00:00:00.000000000 Z
11
+ date: 2015-01-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake