Skip to content

Instantly share code, notes, and snippets.

@xeron
Created August 25, 2009 19:56
Show Gist options
  • Select an option

  • Save xeron/174975 to your computer and use it in GitHub Desktop.

Select an option

Save xeron/174975 to your computer and use it in GitHub Desktop.
>> class Numeric
>> def sqrt
>> Math.sqrt self
>> end
>> def cbrt
>> neg = self < 0
>> c = abs.sqrt.sqrt
>> i = 2
>> loop do
?> w = c
>> i.times { w = w.sqrt }
>> i *= 2
>> w *= c
>> break if c == w
>> c = w
>> end
>> neg ? -c : c
>> end
>> end
=> nil
>> a = 9999999999*9999999999*9999999999
=> 999999999700000000029999999999
>> a.cbrt
=> 9999999999.0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment