Learn and Learn

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

Ruby – Find Natural Logarithm – log() Method – Examples & Explanation

log() is a method in CMath class which is used to find the natural logarithm of a given complex number in Ruby language and if a second argument is given in the code, it will be the base of the logarithm.

log() Method in Ruby

log() method exists in Standard CMath Library of Ruby. The purpose of this method is to provide natural logarithm of a given complex number.


Syntax of the log() Method in Ruby

Syntax of log() method is:


Parameter of log() Method in Ruby

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

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


Return Value of log()

log() method will return natural logarithm of a given complex number.


Ruby log() Example 1




Ruby log() Example 2




Ruby log() Example 3




Ruby log() Example 4




LearnAndLearn.com © 2018 - All rights reserved