Learn and Learn

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

Ruby – Find Principal Value of Cube Root – cbrt() Method with Examples

In Ruby, you can use cbrt() method to find the Principal value of cube root of any given complex number in Ruby language. cbrt() method exists in CMath library of Ruby programming.

cbrt() Method in Ruby

cbrt() method exists in Standard CMath Library of Ruby. The purpose of this method is to know the Principal value of cube root of any given complex number.

 

Syntax of the cbrt() Method in Ruby

Syntax of cbrt() method is:

 

Parameter of cbrt() Method in Ruby

Parameter Description
x Any valid complex number. This parameter is required.

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

 

Return Value of cbrt()

cbrt() method will return the principal value of cube root of any given complex number.

 

Ruby – Get the cbrt() of the Given Numbers


Output

 2.1906531808449907+0.27935211172825947i

 

Ruby – Caluclating cbrt() of Given Numbers Example 1


Output

1.337252615779997+1.757485249628818i

 

Ruby – Caluclating cbrt() of Given Numbers Example 2


Output
1.3747296369986026+0.7937005259840996i

 

Ruby – Non-Complex Numbers always Produces Error in cbrt Method


Output

Error

 

Ruby – Calculating the Negative Values in cbrt() Method


Output

Error

 

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