new_operators 0.0.5 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,3 @@
1
1
  module NewOperators
2
- VERSION = "0.0.5"
2
+ VERSION = "0.0.6"
3
3
  end
data/lib/new_operators.rb CHANGED
@@ -1,9 +1,15 @@
1
1
  class Fixnum
2
2
  def ^(x)
3
- product = x
4
- x.times do
5
- product = product * self
3
+ return 'no negative exponents' if x < 0
4
+ return 'no negative numbers' if self < 0
5
+ product, remainder = self, nil
6
+ return 'undefined' if self == 0 && x == 0
7
+ return 1 if x == 0
8
+ return self if x == 1
9
+ (x % 2 == 0) ? (remainder = 1) : (remainder = self; x = x - 1)
10
+ (x-1).times do
11
+ product = product * self
6
12
  end
7
- return product
13
+ return product * remainder
8
14
  end
9
15
  end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: new_operators
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.0.5
5
+ version: 0.0.6
6
6
  platform: ruby
7
7
  authors:
8
8
  - Charlie McElfresh