Square root?

Discussion in 'Ruby' started by rayreeves, Jun 17, 2006.

  1. rayreeves

    rayreeves Guest

    What library gives me sqrt?

    Ray Reeves
    rayreeves, Jun 17, 2006
    #1
    1. Advertising

  2. rayreeves

    Jeffrey Guest

    rayreeves wrote:

    >>> What library gives me sqrt?

    >>
    >> irb(main):001:0> Math.sqrt(2)
    >> => 1.4142135623731

    >
    > Much obliged for your attention. As you can tell I am new to Ruby.
    > Your tip works ok but I am not sure what I am doing, I thought I
    > would have to 'require alibrary'. What I need now is 'floor' and
    > that doesn't seem to be a Math method.


    Some modules, like Math, are loaded automatically, so you don't have
    to use 'require' explicitly. Numeric types happen to have their own
    floor methods:

    irb(main):001:0> s2 = Math.sqrt(2)
    => 1.4142135623731
    irb(main):002:0> s2.floor
    => 1
    irb(main):003:0>

    In general, the best tool to use when looking for a particular method
    is ri. The ri command searches for documentation relevant to whatever
    type or method you specify. Here's an example:

    shell>ri -T floor
    More than one method matched your request. You can refine
    your search by asking for information on one of:

    Float#floor, Integer#floor, Numeric#floor

    The Class#method notation means that the method should be called on
    instances of the class, rather than on the class itself. The
    documentation here says that any Float, Integer, or Numeric object
    will have a floor method.
    Jeffrey, Jun 17, 2006
    #2
    1. Advertising

  3. rayreeves

    rayreeves Guest

    Thanks for splendid advice

    Ray Reeves
    rayreeves, Jun 18, 2006
    #3
  4. $ ruby -e 'p 2**0.5'
    1.4142135623731
    Erik Veenstra, Jun 19, 2006
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Luca
    Replies:
    1
    Views:
    1,034
    salman sheikh
    Apr 29, 2004
  2. Replies:
    0
    Views:
    1,203
  3. Christian

    Fix point square root

    Christian, Apr 25, 2005, in forum: VHDL
    Replies:
    5
    Views:
    6,643
    jeppe
    Mar 18, 2010
  4. Jeremy Watts

    'big square root' for BigDecimal

    Jeremy Watts, May 26, 2005, in forum: Java
    Replies:
    4
    Views:
    3,557
    Boudewijn Dijkstra
    May 26, 2005
  5. David Harmon
    Replies:
    2
    Views:
    2,898
    cplusplus
    Jun 14, 2006
Loading...

Share This Page