Ruby – Find Arc Cosine – acos() Method – Examples & Explanation

acos() method can be used to find the arc cosine of the any given complex number in Ruby language.

acos() Method in Ruby

acos() method exists in Standard CMath Library of Ruby. The purpose of this method is to provide perfect arc cosine for the given complex number.

 

Syntax of the acos() Method in Ruby

Syntax of acos() method is:

cmath.acos(x)

 

Parameter of acos() Method in Ruby

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

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

 

Return Value of acos()

acos() method will returns the arc cosine of the given numeric complex number.

 

How to get the acos() Value of Given Numbers in Ruby?

 #import CMath library 
 require 'cmath' 
 x = CMath.acos(1 + 1i) 
 puts x  

Output

0.9045568943023813-1.0612750619050357i

 

Ruby acos() Method Example 2

 #import CMath library 
 require 'cmath' 
 x = CMath.acos(-1 + 1i) 
 puts x  

Output

2.2370357592874117-1.0612750619050357i

 

Ruby – Various Ways to Get the acos() of Given Numbers Example 3

 #import CMath library 
 require 'cmath' 
 x = CMath.acos(0 + 0i) 
 puts x 

Output

1.5707963267948966+0.0i

 

Ruby acos() Method Example 4

 #import CMath library 
 require 'cmath' 
 x = CMath.acos(-5 - 5i) 
 puts x 

Output

2.3511949067802878+2.649196177806475i

 

Ruby acos() Method Example 4

 #import CMath library 
 require 'cmath' 
 x = CMath.acos(-5) 
 puts x 

Output

3.141592653589793-2.2924316695611777i

 

Ruby acos() Method Example 4

 #import CMath library 
 require 'cmath' 
 x = CMath.acos(0) 
 puts x 

Output

1.5707963267948966