[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Square root?

rayreeves

6/17/2006 6:04:00 PM

What library gives me sqrt?

Ray Reeves


4 Answers

Jeff Schwab

6/17/2006 6:21:00 PM

0

rayreeves wrote:
> What library gives me sqrt?

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

Jeff Schwab

6/17/2006 9:31:00 PM

0

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.

rayreeves

6/18/2006 1:29:00 PM

0

Thanks for splendid advice

Ray Reeves


Erik Veenstra

6/19/2006 4:17:00 PM

0

$ ruby -e 'p 2**0.5'
1.4142135623731