Math Package v0.1.0

Source
Unstable API
The package is under active development and its API is not yet stable. Names, signatures, and behavior may change between releases, and this documentation will be updated to match.

The package provides mathematical constants and floating-point functions.

Package: Math

Source: github.com/rux-lang/Rux/tree/main/Packages/Math

Every function is provided for both float64 and float32. Pass float64 arguments to get a float64 result, or float32 for a float32 result — each overload rounds only once, so the float32 result is as accurate as the float64 computation allows.

import Math::{ Pi, Pow, Sin, Sqrt };
import Io::PrintLine;

func Main() -> int {
    PrintLine(Sqrt(2.0));      // 1.4142135623730951
    PrintLine(Pow(2.0, 10.0)); // 1024
    PrintLine(Sin(Pi / 2.0));  // 1
    return 0;
}

Installation

rux add Math
rux install

Constants

NameTypeValueDescription
Pifloat643.14159…Ratio of a circle's circumference to its diameter.
Taufloat646.28318…2 × Pi, a full turn in radians.
HalfPifloat641.57079…Pi / 2.
QuarterPifloat640.78539…Pi / 4.
InvPifloat640.31830…1 / Pi.
InvTaufloat640.15915…1 / Tau.
Efloat642.71828…Euler's number, the base of the natural logarithm.
Log2Efloat641.44269…log₂(e).
Log10Efloat640.43429…log₁₀(e).
Ln2float640.69314…ln(2).
Ln10float642.30258…ln(10).
Sqrt2float641.41421…√2.
InvSqrt2float640.70710…1 / √2.
RadPerDegfloat640.01745…Pi / 180, radians per degree.
DegPerRadfloat6457.29577…180 / Pi, degrees per radian.
import Math::Pi;

let circumference = 2.0 * Pi * radius;

Functions

Elementary operations

FunctionDescription
AbsAbsolute value.
MinThe smaller of two values.
MaxThe larger of two values.
ModFloating-point remainder, signed like the dividend.
PowRaise a base to an exponent.
SqrtSquare root.
CbrtCube root, defined for negative arguments too.
Hypot√(x² + y²), without spurious overflow or underflow.

Rounding

FunctionDescription
FloorRound down to the nearest integer value.
CeilRound up to the nearest integer value.
RoundRound to the nearest integer, ties away from zero.
TruncRound toward zero.

Exponential and logarithmic

FunctionDescription
Expe raised to a power.
Exp22 raised to a power.
LogNatural logarithm.
Log2Base-2 logarithm.
Log10Base-10 logarithm.

Trigonometry

FunctionDescription
SinSine of an angle in radians.
CosCosine of an angle in radians.
TanTangent of an angle in radians.
CotanCotangent of an angle in radians.
ArcSinInverse sine, in radians.
ArcCosInverse cosine, in radians.
ArcTanInverse tangent, in radians.
ArcCotInverse cotangent, in radians.

Hyperbolic

FunctionDescription
SinhHyperbolic sine.
CoshHyperbolic cosine.
TanhHyperbolic tangent.
CotanhHyperbolic cotangent.

Angle conversion

FunctionDescription
DegToRadConvert degrees to radians.
RadToDegConvert radians to degrees.