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


Output

1.151292546497023+1.2490457723982544i

 

Ruby log() Example 2


Output

1.5000000000000002+0.2880804567972364i

 

Ruby log() Example 3


Output

1.4306765580733933+1.9519812658311715i

 

Ruby log() Example 4


Output

Error

 

Loading...
LearnAndLearn.com © 2018 - All rights reserved