Learn and Learn

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

Ruby – Find Sine – sin() Method – Examples & Explanation

sin() method can be used to find the sine of the any given complex number in Ruby language where this number is given in radians. sin() method exists in CMath library of Ruby.

sin() method in Ruby

sin() method exists in Standard CMath Library of Ruby. The purpose of this method is to provide perfect sine of any given complex number where this number is given in radians.

Syntax of the sin() method in Ruby

Syntax of sin() method is:

Parameter of sin() method in Ruby

The parameter x is any valid complex number. This parameter is required.Note: If the x parameter is not a complex number, sin() method will return an error.

Return Value of sin()

sin() method will return the sine of any given complex number where this number is given in radians.

Ruby – Get the sin() of Particular Numbers Example 1


Output
-71.16172106192103+21.048644880883543i

 

Ruby – Get the sin() of Particular Numbers Example 2


Output
71.16172106192103+21.048644880883543i

 

Ruby – Non-Complex Values Produces Error in sin() Example 3


Output
Error

Note: Invalid complex numbers like showing in the above code always gives error.

 

Ruby – Subtraction in sin() method


Output
71.16172106192103-21.048644880883543i

 

Ruby – Getting the direct sin() of any number


Output
0.9893582466233818

 

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