Module: Math
- Defined in:
- math.c
Overview
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.
Constant Summary collapse
- PI =
rb_float_new(atan(1.0)*4.0)
- E =
rb_float_new(exp(1.0))
Class Method Summary collapse
-
.acos(x) ⇒ Float
Computes the arc cosine of x.
-
.acosh(x) ⇒ Float
Computes the inverse hyperbolic cosine of x.
-
.asin(x) ⇒ Float
Computes the arc sine of x.
-
.asinh(x) ⇒ Float
Computes the inverse hyperbolic sine of x.
-
.atan(x) ⇒ Float
Computes the arc tangent of x.
-
.atan2(y, x) ⇒ Float
Computes the arc tangent given y and x.
-
.atanh(x) ⇒ Float
Computes the inverse hyperbolic tangent of x.
-
.cos(x) ⇒ Float
Computes the cosine of x (expressed in radians).
-
.cosh(x) ⇒ Float
Computes the hyperbolic cosine of x (expressed in radians).
-
.erf(x) ⇒ Float
Calculates the error function of x.
-
.erfc(x) ⇒ Float
Calculates the complementary error function of x.
-
.exp(x) ⇒ Float
Returns e**x.
-
.frexp(numeric) ⇒ Array
Returns a two-element array containing the normalized fraction (a
Float
) and exponent (aFixnum
) of numeric. -
.hypot(x, y) ⇒ Float
Returns sqrt(x**2 + y**2), the hypotenuse of a right-angled triangle with sides x and y.
-
.ldexp(flt, int) ⇒ Float
Returns the value of flt*(2**int).
-
.log(numeric) ⇒ Float
Returns the natural logarithm of numeric.
-
.log10(numeric) ⇒ Float
Returns the base 10 logarithm of numeric.
-
.sin(x) ⇒ Float
Computes the sine of x (expressed in radians).
-
.sinh(x) ⇒ Float
Computes the hyperbolic sine of x (expressed in radians).
-
.sqrt(numeric) ⇒ Float
Returns the non-negative square root of numeric.
-
.tan(x) ⇒ Float
Returns the tangent of x (expressed in radians).
-
.tanh ⇒ Float
Computes the hyperbolic tangent of x (expressed in radians).
Instance Method Summary collapse
-
#acos(x) ⇒ Float
private
Computes the arc cosine of x.
-
#acosh(x) ⇒ Float
private
Computes the inverse hyperbolic cosine of x.
-
#asin(x) ⇒ Float
private
Computes the arc sine of x.
-
#asinh(x) ⇒ Float
private
Computes the inverse hyperbolic sine of x.
-
#atan(x) ⇒ Float
private
Computes the arc tangent of x.
-
#atan2(y, x) ⇒ Float
private
Computes the arc tangent given y and x.
-
#atanh(x) ⇒ Float
private
Computes the inverse hyperbolic tangent of x.
-
#cos(x) ⇒ Float
private
Computes the cosine of x (expressed in radians).
-
#cosh(x) ⇒ Float
private
Computes the hyperbolic cosine of x (expressed in radians).
-
#erf(x) ⇒ Float
private
Calculates the error function of x.
-
#erfc(x) ⇒ Float
private
Calculates the complementary error function of x.
-
#exp(x) ⇒ Float
private
Returns e**x.
-
#frexp(numeric) ⇒ Array
private
Returns a two-element array containing the normalized fraction (a
Float
) and exponent (aFixnum
) of numeric. -
#hypot(x, y) ⇒ Float
private
Returns sqrt(x**2 + y**2), the hypotenuse of a right-angled triangle with sides x and y.
-
#ldexp(flt, int) ⇒ Float
private
Returns the value of flt*(2**int).
-
#log(numeric) ⇒ Float
private
Returns the natural logarithm of numeric.
-
#log10(numeric) ⇒ Float
private
Returns the base 10 logarithm of numeric.
-
#sin(x) ⇒ Float
private
Computes the sine of x (expressed in radians).
-
#sinh(x) ⇒ Float
private
Computes the hyperbolic sine of x (expressed in radians).
-
#sqrt(numeric) ⇒ Float
private
Returns the non-negative square root of numeric.
-
#tan(x) ⇒ Float
private
Returns the tangent of x (expressed in radians).
-
#tanh ⇒ Float
private
Computes the hyperbolic tangent of x (expressed in radians).
Class Method Details
.acos(x) ⇒ Float
Computes the arc cosine of x. Returns 0..PI.
122 123 124 |
# File 'math.c', line 122 static VALUE math_acos(obj, x) VALUE obj, x; |
.acosh(x) ⇒ Float
Computes the inverse hyperbolic cosine of x.
252 253 254 |
# File 'math.c', line 252 static VALUE math_acosh(obj, x) VALUE obj, x; |
.asin(x) ⇒ Float
Computes the arc sine of x. Returns 0..PI.
142 143 144 |
# File 'math.c', line 142 static VALUE math_asin(obj, x) VALUE obj, x; |
.asinh(x) ⇒ Float
Computes the inverse hyperbolic sine of x.
272 273 274 |
# File 'math.c', line 272 static VALUE math_asinh(obj, x) VALUE obj, x; |
.atan(x) ⇒ Float
Computes the arc tangent of x. Returns -PI/2 .. PI/2.
162 163 164 |
# File 'math.c', line 162 static VALUE math_atan(obj, x) VALUE obj, x; |
.atan2(y, x) ⇒ Float
Computes the arc tangent given y and x. Returns -PI..PI.
56 57 58 |
# File 'math.c', line 56 static VALUE math_atan2(obj, y, x) VALUE obj, x, y; |
.atanh(x) ⇒ Float
Computes the inverse hyperbolic tangent of x.
287 288 289 |
# File 'math.c', line 287 static VALUE math_atanh(obj, x) VALUE obj, x; |
.cos(x) ⇒ Float
Computes the cosine of x (expressed in radians). Returns -1..1.
73 74 75 |
# File 'math.c', line 73 static VALUE math_cos(obj, x) VALUE obj, x; |
.cosh(x) ⇒ Float
Computes the hyperbolic cosine of x (expressed in radians).
186 187 188 |
# File 'math.c', line 186 static VALUE math_cosh(obj, x) VALUE obj, x; |
.erf(x) ⇒ Float
Calculates the error function of x.
452 453 454 |
# File 'math.c', line 452 static VALUE math_erf(obj, x) VALUE obj, x; |
.erfc(x) ⇒ Float
Calculates the complementary error function of x.
467 468 469 |
# File 'math.c', line 467 static VALUE math_erfc(obj, x) VALUE obj, x; |
.exp(x) ⇒ Float
Returns e**x.
307 308 309 |
# File 'math.c', line 307 static VALUE math_exp(obj, x) VALUE obj, x; |
.frexp(numeric) ⇒ Array
Returns a two-element array containing the normalized fraction (a Float
) and exponent (a Fixnum
) of numeric.
fraction, exponent = Math.frexp(1234) #=> [0.6025390625, 11]
fraction * 2**exponent #=> 1234.0
396 397 398 |
# File 'math.c', line 396 static VALUE math_frexp(obj, x) VALUE obj, x; |
.hypot(x, y) ⇒ Float
Returns sqrt(x**2 + y**2), the hypotenuse of a right-angled triangle with sides x and y.
Math.hypot(3, 4) #=> 5.0
437 438 439 |
# File 'math.c', line 437 static VALUE math_hypot(obj, x, y) VALUE obj, x, y; |
.ldexp(flt, int) ⇒ Float
419 420 421 |
# File 'math.c', line 419 static VALUE math_ldexp(obj, x, n) VALUE obj, x, n; |
.log(numeric) ⇒ Float
Returns the natural logarithm of numeric.
331 332 333 |
# File 'math.c', line 331 static VALUE math_log(obj, x) VALUE obj, x; |
.log10(numeric) ⇒ Float
Returns the base 10 logarithm of numeric.
351 352 353 |
# File 'math.c', line 351 static VALUE math_log10(obj, x) VALUE obj, x; |
.sin(x) ⇒ Float
Computes the sine of x (expressed in radians). Returns -1..1.
89 90 91 |
# File 'math.c', line 89 static VALUE math_sin(obj, x) VALUE obj, x; |
.sinh(x) ⇒ Float
Computes the hyperbolic sine of x (expressed in radians).
212 213 214 |
# File 'math.c', line 212 static VALUE math_sinh(obj, x) VALUE obj, x; |
.sqrt(numeric) ⇒ Float
Returns the non-negative square root of numeric.
371 372 373 |
# File 'math.c', line 371 static VALUE math_sqrt(obj, x) VALUE obj, x; |
.tan(x) ⇒ Float
Returns the tangent of x (expressed in radians).
106 107 108 |
# File 'math.c', line 106 static VALUE math_tan(obj, x) VALUE obj, x; |
.tanh ⇒ Float
Computes the hyperbolic tangent of x (expressed in radians).
237 238 239 |
# File 'math.c', line 237 static VALUE math_tanh(obj, x) VALUE obj, x; |
Instance Method Details
#acos(x) ⇒ Float (private)
Computes the arc cosine of x. Returns 0..PI.
122 123 124 |
# File 'math.c', line 122 static VALUE math_acos(obj, x) VALUE obj, x; |
#acosh(x) ⇒ Float (private)
Computes the inverse hyperbolic cosine of x.
252 253 254 |
# File 'math.c', line 252 static VALUE math_acosh(obj, x) VALUE obj, x; |
#asin(x) ⇒ Float (private)
Computes the arc sine of x. Returns 0..PI.
142 143 144 |
# File 'math.c', line 142 static VALUE math_asin(obj, x) VALUE obj, x; |
#asinh(x) ⇒ Float (private)
Computes the inverse hyperbolic sine of x.
272 273 274 |
# File 'math.c', line 272 static VALUE math_asinh(obj, x) VALUE obj, x; |
#atan(x) ⇒ Float (private)
Computes the arc tangent of x. Returns -PI/2 .. PI/2.
162 163 164 |
# File 'math.c', line 162 static VALUE math_atan(obj, x) VALUE obj, x; |
#atan2(y, x) ⇒ Float (private)
Computes the arc tangent given y and x. Returns -PI..PI.
56 57 58 |
# File 'math.c', line 56 static VALUE math_atan2(obj, y, x) VALUE obj, x, y; |
#atanh(x) ⇒ Float (private)
Computes the inverse hyperbolic tangent of x.
287 288 289 |
# File 'math.c', line 287 static VALUE math_atanh(obj, x) VALUE obj, x; |
#cos(x) ⇒ Float (private)
Computes the cosine of x (expressed in radians). Returns -1..1.
73 74 75 |
# File 'math.c', line 73 static VALUE math_cos(obj, x) VALUE obj, x; |
#cosh(x) ⇒ Float (private)
Computes the hyperbolic cosine of x (expressed in radians).
186 187 188 |
# File 'math.c', line 186 static VALUE math_cosh(obj, x) VALUE obj, x; |
#erf(x) ⇒ Float (private)
Calculates the error function of x.
452 453 454 |
# File 'math.c', line 452 static VALUE math_erf(obj, x) VALUE obj, x; |
#erfc(x) ⇒ Float (private)
Calculates the complementary error function of x.
467 468 469 |
# File 'math.c', line 467 static VALUE math_erfc(obj, x) VALUE obj, x; |
#exp(x) ⇒ Float (private)
Returns e**x.
307 308 309 |
# File 'math.c', line 307 static VALUE math_exp(obj, x) VALUE obj, x; |
#frexp(numeric) ⇒ Array (private)
396 397 398 |
# File 'math.c', line 396 static VALUE math_frexp(obj, x) VALUE obj, x; |
#hypot(x, y) ⇒ Float (private)
437 438 439 |
# File 'math.c', line 437 static VALUE math_hypot(obj, x, y) VALUE obj, x, y; |
#ldexp(flt, int) ⇒ Float (private)
419 420 421 |
# File 'math.c', line 419 static VALUE math_ldexp(obj, x, n) VALUE obj, x, n; |
#log(numeric) ⇒ Float (private)
Returns the natural logarithm of numeric.
331 332 333 |
# File 'math.c', line 331 static VALUE math_log(obj, x) VALUE obj, x; |
#log10(numeric) ⇒ Float (private)
Returns the base 10 logarithm of numeric.
351 352 353 |
# File 'math.c', line 351 static VALUE math_log10(obj, x) VALUE obj, x; |
#sin(x) ⇒ Float (private)
Computes the sine of x (expressed in radians). Returns -1..1.
89 90 91 |
# File 'math.c', line 89 static VALUE math_sin(obj, x) VALUE obj, x; |
#sinh(x) ⇒ Float (private)
Computes the hyperbolic sine of x (expressed in radians).
212 213 214 |
# File 'math.c', line 212 static VALUE math_sinh(obj, x) VALUE obj, x; |
#sqrt(numeric) ⇒ Float (private)
Returns the non-negative square root of numeric.
371 372 373 |
# File 'math.c', line 371 static VALUE math_sqrt(obj, x) VALUE obj, x; |
#tan(x) ⇒ Float (private)
Returns the tangent of x (expressed in radians).
106 107 108 |
# File 'math.c', line 106 static VALUE math_tan(obj, x) VALUE obj, x; |
#tanh ⇒ Float (private)
Computes the hyperbolic tangent of x (expressed in radians).
237 238 239 |
# File 'math.c', line 237 static VALUE math_tanh(obj, x) VALUE obj, x; |