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.