Ruby | Math log2() function Last Updated : 07 Jan, 2020 Summarize Comments Improve Suggest changes Share Like Article Like Report 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() function # Assigning values val1 = 213 val2 = 256 val3 = 27 val4 = 100 # Prints the value returned by log2() puts Math.log2(val1) puts Math.log2(val2) puts Math.log2(val3) puts Math.log2(val4) Output: 7.734709620225838 8.0 4.754887502163468 6.643856189774724 Example 2: CPP # Ruby program for log2() function # Assigning values val1 = 21 val2 = 2 val3 = 19 val4 = 121 # Prints the value returned by log2() puts Math.log2(val1) puts Math.log2(val2) puts Math.log2(val3) puts Math.log2(val4) Output: 4.392317422778761 1.0 4.247927513443585 6.918863237274595 Reference: https://devdocs.io/ruby~2.5/math#method-c-log2 Comment More infoAdvertise with us Next Article Ruby | Math log2() function G gopaldave Follow Improve Article Tags : Ruby Ruby-Methods Ruby Math-class Similar Reads 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 log10() function The log10() function in Ruby returns the base 10 logarithm value of X. Syntax: Math.log10(X) Parameter: The function takes one mandatory parameter X whose base 10 logarithm value is to be returned. Return Value: The function the base 10 logarithm value of X. Example 1: CPP # Ruby program for log10() 1 min read Ruby | Math lgamma() function The lgamma() function in Ruby returns two numbers, one represents the logarithmic gamma of value while the other signifies the sign of gamma of value. Syntax: Math.lgamma(value) Parameter: The function takes one mandatory parameter value whose logarithmic gamma is returned and its sign. Return Value 1 min read Ruby | Math ldexp() function The ldexp() function in Ruby returns the value of fraction * (2^exponent) when fraction and exponent are given as parameters. The fraction is a float value and the exponent is an integer. Syntax: Math.ldexp(fraction, exponent) Parameter: The function takes two mandatory parameter fraction and expone 1 min read Ruby | Math hypot() function The hypot() function in Ruby returns sqrt(l^2 + b^2) when l and b are given as parameters. It eventually returns the hypotenuse of a right-angled triangle with sides l and b. Syntax: Math.hypot(l, b) Parameter: The function takes two mandatory parameter l and b which specifies the length and the bas 1 min read Like