maths 0.0.12 → 0.0.13

Sign up to get free protection for your applications and to get access to all the features.
data/lib/maths/calc.rb CHANGED
@@ -279,7 +279,7 @@ module_eval(<<'.,.,', 'calc.y', 20)
279
279
 
280
280
  module_eval(<<'.,.,', 'calc.y', 21)
281
281
  def _reduce_9(val, _values, result)
282
- result = result.power(val[2].to_r)
282
+ result = result.power(Formatter.big_d_to_rational(val[2]))
283
283
  result
284
284
  end
285
285
  .,.,
data/lib/maths/calc.y CHANGED
@@ -19,7 +19,7 @@ rule
19
19
  | exp '*' exp { result *= val[2] }
20
20
  | exp '/' exp { result /= val[2] }
21
21
  | exp '%' exp { result %= val[2] }
22
- | exp '^' exp { result = result.power(val[2].to_r)}
22
+ | exp '^' exp { result = result.power(Formatter.big_d_to_rational(val[2])) }
23
23
  | '(' exp ')' { result = val[1] }
24
24
  | '|' exp '|' { result = val[1].abs }
25
25
  | '-' NUMBER =UMINUS { result = -val[1] }
@@ -18,5 +18,15 @@ module Maths
18
18
 
19
19
  output
20
20
  end
21
+
22
+ # Public: Converts a BigDecimal to either a float or an int, depending
23
+ # on its precision
24
+ def self.big_d_to_rational(val)
25
+ if val.frac == 0
26
+ val.to_i
27
+ else
28
+ val.to_f
29
+ end
30
+ end
21
31
  end
22
32
  end
data/lib/maths/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Maths
2
- VERSION = "0.0.12"
2
+ VERSION = "0.0.13"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: maths
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.12
4
+ version: 0.0.13
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: