Math structure

May 20, 2026 ยท View on GitHub

Up to index

The Math structure provides standard mathematical functions operating on real values, including trigonometric, logarithmic, exponential, and rounding operations, along with mathematical constants.

Specified by the Standard ML Basis Library.

Synopsis

type real

val pi : real
val e : real
val sqrt : real -> real
val sin : real -> real
val cos : real -> real
val tan : real -> real
val asin : real -> real
val acos : real -> real
val atan : real -> real
val atan2 : real * real -> real
val exp : real -> real
val pow : real * real -> real
val ln : real -> real
val log10 : real -> real
val sinh : real -> real
val cosh : real -> real
val tanh : real -> real

type real

pi

pi is the constant pi (3.141592653...).

e

e is base e (2.718281828...) of the natural logarithm.

sqrt

sqrt x returns the square root of x. sqrt (~0.0) = ~0.0. If x < 0, returns NaN.

sin

sin x returns the sine of x, measured in radians. If x is an infinity, returns NaN.

cos

cos x returns the cosine of x, measured in radians. If x is an infinity, returns NaN.

tan

tan x returns the tangent of x, measured in radians. If x is an infinity, returns NaN. Produces infinities at various finite values, roughly corresponding to the singularities of the tangent function.

asin

asin x returns the arc sine of x. asin is the inverse of sin. Its result is guaranteed to be in the closed interval [-pi / 2, pi / 2]. If the magnitude of x exceeds 1.0, returns NaN.

acos

acos x returns the arc cosine of x. acos is the inverse of cos. Its result is guaranteed to be in the closed interval [0, pi]. If the magnitude of x exceeds 1.0, returns NaN.

atan

atan x returns the arc tangent of x. atan is the inverse of tan. For finite arguments, the result is guaranteed to be in the open interval (-pi / 2, pi / 2). If x is +infinity, it returns pi / 2; if x is -infinity, it returns -pi / 2.

atan2

atan2 (y, x) returns the arc tangent of (y / x) in the closed interval [-pi, pi], corresponding to angles within +-180 degrees. The quadrant of the resulting angle is determined using the signs of both x and y, and is the same as the quadrant of the point (x, y). When x = 0, this corresponds to an angle of 90 degrees, and the result is (real (sign y)) * pi / 2.0.

exp

exp x returns e(x), i.e., e raised to the xth power. If x is +infinity, returns +infinity; if x is -infinity, returns 0.

pow

pow (x, y) returns x(y), i.e., x raised to the yth power. For finite x and y, this is well-defined when x > 0, or when x < 0 and y is integral.

ln

ln x returns the natural logarithm (base e) of x. If x < 0, returns NaN; if x = 0, returns -infinity; if x is infinity, returns infinity.

log10

log10 x returns the decimal logarithm (base 10) of x. If x < 0, returns NaN; if x = 0, returns -infinity; if x is infinity, returns infinity.

sinh

sinh x returns the hyperbolic sine of x, that is, (e(x) - e(-x)) / 2. Among its properties, sinh +-0 = +-0, sinh +-infinity = +-infinity.

cosh

cosh x returns the hyperbolic cosine of x, that is, (e(x) + e(-x)) / 2. Among its properties, cosh +-0 = 1, cosh +-infinity = +-infinity.

tanh

tanh x returns the hyperbolic tangent of x, that is, (sinh x) / (cosh x). Among its properties, tanh +-0 = +-0, tanh +-infinity = +-1.