dentaku 0.2.9 → 0.2.10

Sign up to get free protection for your applications and to get access to all the features.
@@ -126,7 +126,7 @@ module Dentaku
126
126
  when :add then Token.new(:numeric, l + r)
127
127
  when :subtract then Token.new(:numeric, l - r)
128
128
  when :multiply then Token.new(:numeric, l * r)
129
- when :divide then Token.new(:numeric, l / r)
129
+ when :divide then Token.new(:numeric, divide(l, r))
130
130
 
131
131
  when :le then Token.new(:logical, l <= r)
132
132
  when :ge then Token.new(:logical, l >= r)
@@ -143,6 +143,12 @@ module Dentaku
143
143
  end
144
144
  end
145
145
 
146
+ def divide(numerator, denominator)
147
+ quotient, remainder = numerator.divmod(denominator)
148
+ return quotient if remainder == 0
149
+ numerator.to_f / denominator.to_f
150
+ end
151
+
146
152
  def expand_range(left, oper1, middle, oper2, right)
147
153
  [left, oper1, middle, Token.new(:combinator, :and), middle, oper2, right]
148
154
  end
@@ -1,3 +1,3 @@
1
1
  module Dentaku
2
- VERSION = "0.2.9"
2
+ VERSION = "0.2.10"
3
3
  end
@@ -53,6 +53,10 @@ describe Dentaku::Evaluator do
53
53
  it 'should respect explicit grouping' do
54
54
  evaluator.evaluate(token_stream(:open, 1, :add, 1, :close, :multiply, 5)).should eq(10)
55
55
  end
56
+
57
+ it 'should return floating point from division when there is a remainder' do
58
+ evaluator.evaluate(token_stream(5, :divide, 4)).should eq(1.25)
59
+ end
56
60
  end
57
61
 
58
62
  describe 'functions' do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dentaku
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.9
4
+ version: 0.2.10
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-10-17 00:00:00.000000000 Z
12
+ date: 2012-12-10 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake
@@ -87,7 +87,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
87
87
  version: '0'
88
88
  segments:
89
89
  - 0
90
- hash: -4230531870219194848
90
+ hash: -662526630847863998
91
91
  required_rubygems_version: !ruby/object:Gem::Requirement
92
92
  none: false
93
93
  requirements:
@@ -96,7 +96,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
96
96
  version: '0'
97
97
  segments:
98
98
  - 0
99
- hash: -4230531870219194848
99
+ hash: -662526630847863998
100
100
  requirements: []
101
101
  rubyforge_project: dentaku
102
102
  rubygems_version: 1.8.23