Hi,

Am Samstag, 11. Jul 2009, 19:48:50 +0900 schrieb Zangief Ief:
> Is there a cube root (as http://en.wikipedia.org/wiki/Cube_root)
> function in Ruby?  Math module seems not offer it... except a
> Math.sqrt().

I suppose you mean the method mentioned under "Cube root on standard
calculator". Here's an implementation:

  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

If you like it in C (only Ruby 1.8):

  http://bertram-scharpf.homelinux.com:8808/doc_root/bs-ruby-2.3/rdoc/classes/Numeric.src/M000033.html

Bertram


-- 
Bertram Scharpf
Stuttgart, Deutschland/Germany
http://www.bertram-scharpf.de