Type:
Module
Constants:
PI : DBL2NUM(M_PI)
E : DBL2NUM(M_E)

When mathn is required, the Math module changes as follows:

Standard Math module behaviour:

1
2
3
Math.sqrt(4/9)     # => 0.0
Math.sqrt(4.0/9.0) # => 0.666666666666667
Math.sqrt(- 4/9)   # => Errno::EDOM: Numerical argument out of domain - sqrt

After require 'mathn', this is changed to:

1
2
3
4
require 'mathn'
Math.sqrt(4/9)      # => 2/3
Math.sqrt(4.0/9.0# => 0.666666666666667
Math.sqrt(- 4/9)    # => Complex(0, 2/3)

The Math module contains module functions for basic trigonometric and transcendental functions. See class Float for a list of constants that define Ruby's floating point accuracy.

exp
  • References/Ruby on Rails/Ruby/Classes/Math

Math.exp(x) â float Class Public methods Returns e**x.

2025-01-10 15:47:30
rsqrt
  • References/Ruby on Rails/Ruby/Classes/Math

rsqrt(a) Class Public methods Compute square root of a non negative number.

2025-01-10 15:47:30
asin
  • References/Ruby on Rails/Ruby/Classes/Math

Math.asin(x) â float Class Public methods Computes the arc sine of x

2025-01-10 15:47:30
erfc
  • References/Ruby on Rails/Ruby/Classes/Math

Math.erfc(x) â float Class Public methods Calculates the complementary error

2025-01-10 15:47:30
cbrt
  • References/Ruby on Rails/Ruby/Classes/Math

Math.cbrt(numeric) â float Class Public methods Returns the cube root of

2025-01-10 15:47:30
sqrt
  • References/Ruby on Rails/Ruby/Classes/Math

sqrt(a) Class Public methods Computes the square root of a. It

2025-01-10 15:47:30
lgamma
  • References/Ruby on Rails/Ruby/Classes/Math

Math.lgamma(x) â [float, -1 or 1] Class Public methods Calculates the logarithmic

2025-01-10 15:47:30
sin
  • References/Ruby on Rails/Ruby/Classes/Math

Math.sin(x) â float Class Public methods Computes the sine of x

2025-01-10 15:47:30
acos
  • References/Ruby on Rails/Ruby/Classes/Math

Math.acos(x) â float Class Public methods Computes the arc cosine of x

2025-01-10 15:47:30
atan2
  • References/Ruby on Rails/Ruby/Classes/Math

Math.atan2(y, x) â float Class Public methods Computes the arc tangent given

2025-01-10 15:47:30