Ruby | Math sqrt() function Last Updated : 07 Jan, 2020 Summarize Comments Improve Suggest changes Share Like Article Like Report The sqrt() is an inbuilt function in Ruby returns the square root of a given value. Syntax: Math.sqrt(value) Parameters: The function accepts one mandatory parameter value whose square root is to be returned. Return Value: It returns the square root of the value. Example 1: CPP #Ruby program for sqrt() function #Assigning values val1 = 4 val2 = 9 val3 = 64 val4 = 100 #Prints the sqrt() value puts Math.sqrt(val1) puts Math.sqrt(val2) puts Math.sqrt(val3) puts Math.sqrt(val4) Output: 2.0 3.0 8.0 10.0 Example 2: CPP #Ruby program for sqrt() function #Assigning values val1 = 40 val2 = 19 val3 = 164 val4 = 1200 #Prints the sqrt() value puts Math.sqrt(val1) puts Math.sqrt(val2) puts Math.sqrt(val3) puts Math.sqrt(val4) Output: 6.324555320336759 4.358898943540674 12.806248474865697 34.64101615137755 Reference: https://devdocs.io/ruby~2.5/math#method-c-sqrt Comment More infoAdvertise with us Next Article Ruby | Math sqrt() function G gopaldave Follow Improve Article Tags : Ruby Ruby-Methods Ruby Collections Ruby Math-class Similar Reads Ruby | Math sin() function The sin() is an inbuilt function in Ruby returns the sine of a given angle expressed in radians which is in range [-inf, +inf]. The returned value is in range [-1, +1]. Syntax: Math.sin(value) Parameters: The function accepts one mandatory parameter value whose corresponding sine is returned. Ret 1 min read Ruby | Integer sqrt() function The sqrt() function in Ruby returns the integer square root of the non-negative integer n, i.e. the largest non-negative integer less than or equal to the square root of n Syntax: Integer.sqrt(number) Parameter: The function takes the integer whose square root is to be returned. It throws an error " 1 min read Ruby | Math log() function The log() function in Ruby returns the logarithm value of X. The second parameter is the base given by the user to which the logarithm value is returned. In case its not given, then the default base is e. Syntax: Math.log(X, base) Parameter: The function takes one mandatory parameter X whose logarit 1 min read Ruby | Math cbrt() function The cbrt() is an inbuilt function in Ruby returns the cube root of a given value. Syntax: Math.cbrt(value) Parameters: The function accepts one mandatory parameter value whose cuberoot is to be returned. Return Value: It returns the cuberoot of the value. Example 1: Ruby #Ruby program for cbrt() 1 min read Ruby | Math log2() function The log2() function in Ruby returns the base 2 logarithm value of X. Syntax: Math.log2(X) Parameter: The function takes one mandatory parameter X whose base 2 logarithm value is to be returned. Return Value: The function the base 2 logarithm value of X. Example 1: CPP # Ruby program for log2() funct 1 min read Like