Skip to content

Instantly share code, notes, and snippets.

@etale
Created October 15, 2010 14:17
Show Gist options
  • Save etale/628250 to your computer and use it in GitHub Desktop.
Save etale/628250 to your computer and use it in GitHub Desktop.
log
class Real
def log
return if zero?
_ = self
return (- _).log if _ < zero
if _ > 2 or _ < unity
e = 0
e, _ = e + 1, _ / 2 while _ > 2
e, _ = e - 1, _ * 2 while _ < 1
_.log + e * 2.log
else
_ = x = unity - inverse
t = 1
i, r = 1, 0
until t.zero?
r += t
i += 1
_ *= x
t = _ / i
end
r
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment