Skip to content

Latest commit

 

History

History
45 lines (36 loc) · 2.84 KB

math_functions_in_ruby.md

File metadata and controls

45 lines (36 loc) · 2.84 KB

Math functions with Ruby

The Ruby Math module provides the Ruby programmer with an extensive range of methods for performing mathematical tasks.

Math methods

There is a list of methods with their description

Method name Description
Math.acos, Math.acos! Arc cosine
Math.acosh, Math.acosh! Hyperbolic arc cosine
Math.asin, Math.asin! Arc sine
Math.asinh, Math.asinh Hyperbolic arc sine
Math.atan, Math.atan!, Math.atan2, Math.atan2! Arc tangent. atan takes an x argument. atan2 takes x and y arguments
Math.atanh, Math.atanh! Hyperbolic arc tangent
Math.cos, Math.cos! Cosine
Math.cosh, Math.cosh Hyperbolic cosine
Math.sin, Math.sin! Sine
Math.erf Error function
Match.erfc Complementary error function
Math.exp, Math.exp! Base x of Euler
Math.frexp Normalized fraction and exponent
Math.hypot Hypotenuse
Math.ldexp Floating-point value corresponding to mantissa and exponent
Math.sinh, Math.sinh! Hyperbolic sine
Math.sqrt, Math.sqrt! Square root
Math.tan, Math.tan! Tangent
Math.tanh, Math.tanh! Hyperbolic tangent

Some examples

To perform a square root

Math.sqrt(9)
=> 3.0

Euler calculation

Math.exp(2)
=> 7.38905609893065