← index

Mathabstract

inherits Object

A namespace of mathematical constants and free functions -- Math.sin: x where a method hung off the number would read awkwardly. Number-centric operations (abs, floor, sqrt, pow:, min:, max:) live on Integer/Double; sqrt: and pow:to: are mirrored here in free-function style. Every function accepts an Integer or a Double and returns a Double; angles are in radians.

Class methods

acos:

The arccosine, in radians in [0, pi]; an argument outside [-1, 1] yields NaN.

Math.acos:1     "* -> 0

native

asin:

The arcsine, in radians in [-pi/2, pi/2]; an argument outside [-1, 1] yields NaN.

Math.asin:1     "* -> 1.5707963267948966

native

atan:

The arctangent, in radians in (-pi/2, pi/2). For the angle of a vector, prefer atan:over:, which keeps the quadrant.

native

atan: over:

The angle of the vector (x, y) in radians in (-pi, pi] -- atan2, reading Math.atan: y over: x. Unlike atan: of y/x it keeps the quadrant and handles a zero x.

Math.atan:1 over:1     "* -> 0.7853981633974483

native

cos:

The cosine of an angle in radians.

Math.cos:0     "* -> 1

native

e

Euler's number, the base of the natural logarithm.

Math.e     "* -> 2.718281828459045

native

exp:

e raised to the argument's power.

Math.exp:1     "* -> 2.718281828459045

native

hypot: over:

The hypotenuse sqrt(a^2 + b^2) of a right triangle with legs a and b, computed without intermediate overflow.

Math.hypot:3 over:4     "* -> 5

native

ln:

The natural (base-e) logarithm. The domain is guarded: a zero or negative argument raises an ArithmeticError rather than returning NaN.

Math.ln:Math.e     "* -> 1

native

log2:

The base-2 logarithm (domain-guarded like ln:).

Math.log2:8     "* -> 3

native

log:

The base-10 logarithm (domain-guarded like ln:).

Math.log:1000     "* -> 3

native

log: base:

The logarithm of the first argument in the base given by the second (the argument is domain-guarded like ln:).

Math.log:8 base:2     "* -> 3

native

pi

The circle constant pi.

Math.pi     "* -> 3.141592653589793

native

pow: to:

The first argument raised to the second's power, mirroring pow: on the numbers; always computed in floating point.

Math.pow:2 to:10     "* -> 1024

native

sin:

The sine of an angle in radians.

Math.sin:(Math.pi / 2)     "* -> 1

native

sqrt:

The square root, mirroring sqrt on the numbers in free-function style; a negative argument raises an ArithmeticError.

Math.sqrt:2     "* -> 1.4142135623730951

native

tan:

The tangent of an angle in radians.

native

tau

Tau = 2 pi, one full turn in radians.

Math.tau     "* -> 6.283185307179586

native