Ruby Tutorial Ruby References

Ruby - Math.asin() Method



The Ruby Math.asin() method returns arc sine of a value. The return value will be of float type and in the range -𝜋/2 through 𝜋/2.

Note: asin() is the inverse of sin().

Syntax

Math.asin(x)

Parameters

x Specify the value.

Return Value

Returns the arc sine of the value.

Example:

In the example below, Math.asin() method is used to find out the arc sine of a given value.

puts "Math.asin(0) = #{Math.asin(0)}"
puts "Math.asin(0.5) = #{Math.asin(0.5)}"
puts "Math.asin(1) = #{Math.asin(1)}"
puts "Math.asin(-0.5) = #{Math.asin(-0.5)}"
puts "Math.asin(-1) = #{Math.asin(-1)}"

The output of the above code will be:

Math.asin(0) = 0.0
Math.asin(0.5) = 0.5235987755982989
Math.asin(1) = 1.5707963267948966
Math.asin(-0.5) = -0.5235987755982989
Math.asin(-1) = -1.5707963267948966

❮ Ruby Math Module

5