0

Square root in Ruby

How could I calculate the square root in Ruby? I've tried sqrt() and math.sqrt(), but none of them worked.

19th Jun 2019, 1:35 PM
Milo Draco
Milo Draco - avatar
2 ответов
+ 9
You have to import CMath library . for example:- require 'cmath' x = CMath.sqrt(5) puts x
19th Jun 2019, 1:59 PM
A͢J
A͢J - avatar
+ 2
I just figured it out: I have to write Math.sqrt, in high case. Thanks, guys.
19th Jun 2019, 3:31 PM
Milo Draco
Milo Draco - avatar