module Math
Floating-point functions, as Ruby's Math: angles are in radians.
An argument outside a function's domain gives NaN (or an infinity)
instead of raising a domain error as Ruby does: Math.sqrt(-1.0) is NaN,
Math.log(0.0) is -Float::INFINITY. An Int argument is taken as a
Float.
Math.sqrt(2.0) # => 1.4142135623730951
Math.sin(Math::PI / 2) # => 1.0
Math.hypot(3.0, 4.0) # => 5.0
Math.sqrt(-1.0).nan? # => true
<prelude>:6646
Constants
PI: Float
The ratio of a circle's circumference to its diameter.
<prelude>:6648
E: Float
The base of the natural logarithm.
<prelude>:6650
Class methods
def self.sqrt(x: Float) -> Float
The square root; NaN for a negative x.
<prelude>:6653
def self.sqrt(x: Int) -> Float
The square root, as a Float (Int.sqrt gives the integer one);
NaN for a negative x.
<prelude>:6656
def self.cbrt(x: Float) -> Float
The cube root, negative for a negative x (Math.cbrt(-27.0) is
-3.0).
<prelude>:6659
def self.sin(x: Float) -> Float
The sine of x radians.
<prelude>:6661
def self.cos(x: Float) -> Float
The cosine of x radians.
<prelude>:6663
def self.tan(x: Float) -> Float
The tangent of x radians.
<prelude>:6665
def self.atan(x: Float) -> Float
The arctangent, in radians from -PI/2 to PI/2.
<prelude>:6667
def self.atan2(y: Float, x: Float) -> Float
The angle from the positive x axis to the point (x, y), in radians
from -PI to PI: unlike atan(y / x), it tells the quadrant.
Math.atan2(1.0, 1.0) # => 0.7853981633974483
Math.atan2(1.0, -1.0) # => 2.356194490192345
<prelude>:6675
def self.exp(x: Float) -> Float
E raised to the power x.
<prelude>:6677
def self.log(x: Float) -> Float
The natural logarithm; -Float::INFINITY for 0.0, NaN for a negative
x.
<prelude>:6680
def self.log(x: Float, base: Float) -> Float
The logarithm in base, log(x) / log(base).
Math.log(8.0, 2.0) # => 3.0
Math.log(100.0, 10.0) # => 2.0
<prelude>:6687
def self.log2(x: Float) -> Float
The base-2 logarithm.
<prelude>:6689
def self.log10(x: Float) -> Float
The base-10 logarithm.
<prelude>:6691
def self.pow(x: Float, y: Float) -> Float
x raised to the power y, as Float#**: NaN for a negative x
and a fractional y.
<prelude>:6694
def self.hypot(x: Float, y: Float) -> Float
The length of the hypotenuse, sqrt(x * x + y * y), without
overflow or underflow in between.
<prelude>:6697
def self.floor(x: Float) -> Int
The largest Int not above x, as Float#floor: RangeError for
NaN or an infinity.
<prelude>:6700
def self.ceil(x: Float) -> Int
The smallest Int not below x, as Float#ceil: RangeError for
NaN or an infinity.
<prelude>:6703
def self.asin(x: Float) -> Float
The arcsine, in radians from -PI/2 to PI/2; NaN outside -1.0..1.0.
<prelude>:6705
def self.acos(x: Float) -> Float
The arccosine, in radians from 0 to PI; NaN outside -1.0..1.0.
<prelude>:6707
def self.sinh(x: Float) -> Float
The hyperbolic sine.
<prelude>:6709
def self.cosh(x: Float) -> Float
The hyperbolic cosine.
<prelude>:6711
def self.tanh(x: Float) -> Float
The hyperbolic tangent, from -1.0 to 1.0.
<prelude>:6713
def self.asinh(x: Float) -> Float
The inverse hyperbolic sine.
<prelude>:6715
def self.acosh(x: Float) -> Float
The inverse hyperbolic cosine; NaN below 1.0.
<prelude>:6717
def self.atanh(x: Float) -> Float
The inverse hyperbolic tangent; an infinity at -1.0 and 1.0, NaN beyond them.
<prelude>:6720
def self.log1p(x: Float) -> Float
log(1 + x), accurate for an x near 0, where 1 + x would lose
its digits.
Math.log1p(1.0e-10) # => 9.999999999500001e-11
<prelude>:6727
def self.expm1(x: Float) -> Float
exp(x) - 1, accurate for an x near 0.
<prelude>:6729