Ruby | Integer sqrt() function Last Updated : 07 Jan, 2020 Summarize Comments Improve Suggest changes Share Like Article Like Report 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 "out of domain" if a negative number is passed. Return Value: The function returns the integer square root. Example 1: CPP #Ruby program for sqrt() function #Initializing the number num1 = 25 num2 = 16 num3 = 100 num4 = 5 #Prints the sqrt of a number puts Integer.sqrt(num1) puts Integer.sqrt(num2) puts Integer.sqrt(num3) puts Integer.sqrt(num4) Output: 5 4 10 2 Example 2: CPP #Ruby program for sqrt() function #Initializing the number num1 = 64 num2 = 81 num3 = 49 num4 = 36 #Prints the sqrt of a number puts Integer.sqrt(num1) puts Integer.sqrt(num2) puts Integer.sqrt(num3) puts Integer.sqrt(num4) Output: 8 9 7 6 Reference: https://devdocs.io/ruby~2.5/integer#method-c-sqrt Comment More infoAdvertise with us Next Article Ruby | Integer sqrt() function G gopaldave Follow Improve Article Tags : Ruby Ruby-Methods Ruby Collections Ruby Integer-class Similar Reads Ruby | Math sqrt() function 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 sqr 1 min read Ruby | Integer << function The << is an inbuilt method in Ruby returns the number which is shifted N times to the left. The resultant number is num * (2^N). Syntax: num << N Parameters: The function accepts no parameter. Return Value: It returns num * (2^N). Example 1: Ruby # Ruby program for << method in In 1 min read Ruby | Numeric to_int() function The to_int() is an inbuilt method in Ruby returns the integer part of the given number. Syntax: num.to_int() Parameters: The function needs the number whose integer part is to be returned. Return Value: It returns the integer part. Example 1: Ruby # Ruby program for to_int() # method in Numeric # In 1 min read Ruby | Numeric integer() function The integer?() is an inbuilt method in Ruby returns a boolean value. It returns true if the number is an integer one, else it returns false. Syntax: num.integer?() Parameters: The function needs a number which is to be checked for. Return Value: It returns returns a boolean value. Example 1: CPP # R 1 min read Ruby Integer to_s function with example The to_s function in Ruby returns a string containing the place-value representation of int with radix base (between 2 and 36). If no base is provided in the parameter then it assumes the base to be 10 and returns. Syntax: number.to_s(base) Parameter: The function takes the number and a base to whi 1 min read Like