Created
June 16, 2017 21:54
-
-
Save evidanary/9fc08166e5236e9f83dae9ff25a1e447 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# power of a number | |
# Beware the power can be a float or negative | |
def pow(x,y) | |
return 1 if y==0 | |
product = 1 | |
(1..y.abs).each do | |
product /= x.to_f if y<0 | |
product *= x if y>0 | |
end | |
product | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment