Learn and Learn

Learn And Learn - great place for tutorials, references and how-to

Ruby – Find Base 2 Logarithm – log2() Method – Examples & Explanation

log2() is a method in CMath class which is used to find the base 2 logarithm of any given complex number in Ruby language.

log2() Method in Ruby

log2() method exists in Standard CMath Library of Ruby. The purpose of this method is to provide base 2 logarithm of any given complex number.


Syntax of the log2() Method in Ruby

Syntax of log2() Method is:


Parameters of log2() Method in Ruby

Parameter Description
xAny valid complex number. This parameter is required.

Note: If the x parameter is not a complex number, log2() method will return an error.


Return Value of log2()

log2() method will return base 2 logarithm of a given complex number.


Ruby – Get log2() of Particular Number




Ruby Negative log2() Function




Ruby – Non-Complex Number in log2() Produces Error




Ruby log2() Function




LearnAndLearn.com © 2018 - All rights reserved