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 +1 -1
- data/lib/maths/calc.y +1 -1
- data/lib/maths/formatter.rb +10 -0
- data/lib/maths/version.rb +1 -1
- metadata +1 -1
data/lib/maths/calc.rb
CHANGED
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]
|
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] }
|
data/lib/maths/formatter.rb
CHANGED
@@ -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