gdDocumentation0.8.0

API reference

GD.math

Entry for standard mathematical functions, IEEE 754 special values, and bit conversions.

Properties

bits : GD.math.bits

Integer math entry for uint64 bit counts, rotations, reversals, and operations with carry.

e : float
pi : float
phi : float
sqrt2 : float
sqrt_e : float
sqrt_pi : float
sqrt_phi : float
ln2 : float
log2_e : float
ln10 : float
log10_e : float
max_float64 : float
smallest_nonzero_float64 : float

Methods

abs

abs(x: float) -> float

Provide unary mathematical functions.

Parameters

NameTypeDefaultDescription
xfloatRequiredNumeric input; direct trigonometric functions take radians.

Return value

float

Errors

This call has no Err return slot. Its return type and documented sentinel values determine how to inspect the result.

acos

acos(x: float) -> float

Return inverse cosine.

Parameters

NameTypeDefaultDescription
xfloatRequiredNumeric input; direct trigonometric functions take radians.

Return value

float

Errors

This call has no Err return slot. Its return type and documented sentinel values determine how to inspect the result.

acosh

acosh(x: float) -> float

Return inverse hyperbolic cosine.

Parameters

NameTypeDefaultDescription
xfloatRequiredNumeric input; direct trigonometric functions take radians.

Return value

float

Errors

This call has no Err return slot. Its return type and documented sentinel values determine how to inspect the result.

asin

asin(x: float) -> float

Return inverse sine.

Parameters

NameTypeDefaultDescription
xfloatRequiredNumeric input; direct trigonometric functions take radians.

Return value

float

Errors

This call has no Err return slot. Its return type and documented sentinel values determine how to inspect the result.

asinh

asinh(x: float) -> float

Return inverse hyperbolic sine.

Parameters

NameTypeDefaultDescription
xfloatRequiredNumeric input; direct trigonometric functions take radians.

Return value

float

Errors

This call has no Err return slot. Its return type and documented sentinel values determine how to inspect the result.

atan

atan(x: float) -> float

Return inverse tangent.

Parameters

NameTypeDefaultDescription
xfloatRequiredNumeric input; direct trigonometric functions take radians.

Return value

float

Errors

This call has no Err return slot. Its return type and documented sentinel values determine how to inspect the result.

atanh

atanh(x: float) -> float

Return inverse hyperbolic tangent.

Parameters

NameTypeDefaultDescription
xfloatRequiredNumeric input; direct trigonometric functions take radians.

Return value

float

Errors

This call has no Err return slot. Its return type and documented sentinel values determine how to inspect the result.

cbrt

cbrt(x: float) -> float

Return cube root.

Parameters

NameTypeDefaultDescription
xfloatRequiredNumeric input; direct trigonometric functions take radians.

Return value

float

Errors

This call has no Err return slot. Its return type and documented sentinel values determine how to inspect the result.

ceil

ceil(x: float) -> float

Round toward positive infinity.

Parameters

NameTypeDefaultDescription
xfloatRequiredNumeric input; direct trigonometric functions take radians.

Return value

float

Errors

This call has no Err return slot. Its return type and documented sentinel values determine how to inspect the result.

cos

cos(x: float) -> float

Return cosine.

Parameters

NameTypeDefaultDescription
xfloatRequiredNumeric input; direct trigonometric functions take radians.

Return value

float

Errors

This call has no Err return slot. Its return type and documented sentinel values determine how to inspect the result.

cosh

cosh(x: float) -> float

Return hyperbolic cosine.

Parameters

NameTypeDefaultDescription
xfloatRequiredNumeric input; direct trigonometric functions take radians.

Return value

float

Errors

This call has no Err return slot. Its return type and documented sentinel values determine how to inspect the result.

erf

erf(x: float) -> float

Return the error function.

Parameters

NameTypeDefaultDescription
xfloatRequiredNumeric input; direct trigonometric functions take radians.

Return value

float

Errors

This call has no Err return slot. Its return type and documented sentinel values determine how to inspect the result.

erfc

erfc(x: float) -> float

Return the complementary error function.

Parameters

NameTypeDefaultDescription
xfloatRequiredNumeric input; direct trigonometric functions take radians.

Return value

float

Errors

This call has no Err return slot. Its return type and documented sentinel values determine how to inspect the result.

erfinv

erfinv(x: float) -> float

Return inverse error function.

Parameters

NameTypeDefaultDescription
xfloatRequiredNumeric input; direct trigonometric functions take radians.

Return value

float

Errors

This call has no Err return slot. Its return type and documented sentinel values determine how to inspect the result.

erfcinv

erfcinv(x: float) -> float

Return inverse complementary error function.

Parameters

NameTypeDefaultDescription
xfloatRequiredNumeric input; direct trigonometric functions take radians.

Return value

float

Errors

This call has no Err return slot. Its return type and documented sentinel values determine how to inspect the result.

exp

exp(x: float) -> float

Return the natural exponential.

Parameters

NameTypeDefaultDescription
xfloatRequiredNumeric input; direct trigonometric functions take radians.

Return value

float

Errors

This call has no Err return slot. Its return type and documented sentinel values determine how to inspect the result.

exp2

exp2(x: float) -> float

Return the base-two exponential.

Parameters

NameTypeDefaultDescription
xfloatRequiredNumeric input; direct trigonometric functions take radians.

Return value

float

Errors

This call has no Err return slot. Its return type and documented sentinel values determine how to inspect the result.

expm1

expm1(x: float) -> float

Return the natural exponential minus one.

Parameters

NameTypeDefaultDescription
xfloatRequiredNumeric input; direct trigonometric functions take radians.

Return value

float

Errors

This call has no Err return slot. Its return type and documented sentinel values determine how to inspect the result.

floor

floor(x: float) -> float

Round toward negative infinity.

Parameters

NameTypeDefaultDescription
xfloatRequiredNumeric input; direct trigonometric functions take radians.

Return value

float

Errors

This call has no Err return slot. Its return type and documented sentinel values determine how to inspect the result.

gamma

gamma(x: float) -> float

Return the Gamma function.

Parameters

NameTypeDefaultDescription
xfloatRequiredNumeric input; direct trigonometric functions take radians.

Return value

float

Errors

This call has no Err return slot. Its return type and documented sentinel values determine how to inspect the result.

ilogb

ilogb(x: float) -> int

Return the binary exponent as an integer.

Parameters

NameTypeDefaultDescription
xfloatRequiredNumeric input; direct trigonometric functions take radians.

Return value

int

Errors

This call has no Err return slot. Its return type and documented sentinel values determine how to inspect the result.

j0

j0(x: float) -> float

Normalize platform C-math Bessel functions to the public contract.

Parameters

NameTypeDefaultDescription
xfloatRequiredNumeric input; direct trigonometric functions take radians.

Return value

float

Errors

This call has no Err return slot. Its return type and documented sentinel values determine how to inspect the result.

j1

j1(x: float) -> float

Return the first-kind Bessel function of order one.

Parameters

NameTypeDefaultDescription
xfloatRequiredNumeric input; direct trigonometric functions take radians.

Return value

float

Errors

This call has no Err return slot. Its return type and documented sentinel values determine how to inspect the result.

log

log(x: float) -> float

Return the natural logarithm.

Parameters

NameTypeDefaultDescription
xfloatRequiredNumeric input; direct trigonometric functions take radians.

Return value

float

Errors

This call has no Err return slot. Its return type and documented sentinel values determine how to inspect the result.

log1p

log1p(x: float) -> float

Return the natural logarithm of one plus the input.

Parameters

NameTypeDefaultDescription
xfloatRequiredNumeric input; direct trigonometric functions take radians.

Return value

float

Errors

This call has no Err return slot. Its return type and documented sentinel values determine how to inspect the result.

log2

log2(x: float) -> float

Return the base-two logarithm.

Parameters

NameTypeDefaultDescription
xfloatRequiredNumeric input; direct trigonometric functions take radians.

Return value

float

Errors

This call has no Err return slot. Its return type and documented sentinel values determine how to inspect the result.

log10

log10(x: float) -> float

Return the base-ten logarithm.

Parameters

NameTypeDefaultDescription
xfloatRequiredNumeric input; direct trigonometric functions take radians.

Return value

float

Errors

This call has no Err return slot. Its return type and documented sentinel values determine how to inspect the result.

logb

logb(x: float) -> float

Return the binary exponent as a floating-point value.

Parameters

NameTypeDefaultDescription
xfloatRequiredNumeric input; direct trigonometric functions take radians.

Return value

float

Errors

This call has no Err return slot. Its return type and documented sentinel values determine how to inspect the result.

round

round(x: float) -> float

Round to the nearest integer with ties away from zero.

Parameters

NameTypeDefaultDescription
xfloatRequiredNumeric input; direct trigonometric functions take radians.

Return value

float

Errors

This call has no Err return slot. Its return type and documented sentinel values determine how to inspect the result.

round_to_even

round_to_even(x: float) -> float

Round ties to even, preserving signed zero and large integral values.

Parameters

NameTypeDefaultDescription
xfloatRequiredNumeric input; direct trigonometric functions take radians.

Return value

float

Errors

This call has no Err return slot. Its return type and documented sentinel values determine how to inspect the result.

signbit

signbit(x: float) -> bool

Report whether the sign bit is set.

Parameters

NameTypeDefaultDescription
xfloatRequiredNumeric input; direct trigonometric functions take radians.

Return value

bool

Errors

This call has no Err return slot. Its return type and documented sentinel values determine how to inspect the result.

sin

sin(x: float) -> float

Return sine.

Parameters

NameTypeDefaultDescription
xfloatRequiredNumeric input; direct trigonometric functions take radians.

Return value

float

Errors

This call has no Err return slot. Its return type and documented sentinel values determine how to inspect the result.

sinh

sinh(x: float) -> float

Return hyperbolic sine.

Parameters

NameTypeDefaultDescription
xfloatRequiredNumeric input; direct trigonometric functions take radians.

Return value

float

Errors

This call has no Err return slot. Its return type and documented sentinel values determine how to inspect the result.

sqrt

sqrt(x: float) -> float

Return square root.

Parameters

NameTypeDefaultDescription
xfloatRequiredNumeric input; direct trigonometric functions take radians.

Return value

float

Errors

This call has no Err return slot. Its return type and documented sentinel values determine how to inspect the result.

tan

tan(x: float) -> float

Return tangent.

Parameters

NameTypeDefaultDescription
xfloatRequiredNumeric input; direct trigonometric functions take radians.

Return value

float

Errors

This call has no Err return slot. Its return type and documented sentinel values determine how to inspect the result.

tanh

tanh(x: float) -> float

Return hyperbolic tangent.

Parameters

NameTypeDefaultDescription
xfloatRequiredNumeric input; direct trigonometric functions take radians.

Return value

float

Errors

This call has no Err return slot. Its return type and documented sentinel values determine how to inspect the result.

trunc

trunc(x: float) -> float

Truncate the fractional part toward zero.

Parameters

NameTypeDefaultDescription
xfloatRequiredNumeric input; direct trigonometric functions take radians.

Return value

float

Errors

This call has no Err return slot. Its return type and documented sentinel values determine how to inspect the result.

y0

y0(x: float) -> float

Return the second-kind Bessel function of order zero.

Parameters

NameTypeDefaultDescription
xfloatRequiredNumeric input; direct trigonometric functions take radians.

Return value

float

Errors

This call has no Err return slot. Its return type and documented sentinel values determine how to inspect the result.

y1

y1(x: float) -> float

Return the second-kind Bessel function of order one.

Parameters

NameTypeDefaultDescription
xfloatRequiredNumeric input; direct trigonometric functions take radians.

Return value

float

Errors

This call has no Err return slot. Its return type and documented sentinel values determine how to inspect the result.

float64_bits

float64_bits(x: float) -> int

Convert between floating-point values and IEEE 754 integer bit patterns.

Parameters

NameTypeDefaultDescription
xfloatRequiredNumeric input; direct trigonometric functions take radians.

Return value

int

Errors

This call has no Err return slot. Its return type and documented sentinel values determine how to inspect the result.

float64_from_bits

float64_from_bits(x: int) -> float

Construct a double from its bit pattern.

Parameters

NameTypeDefaultDescription
xintRequiredInteger carrying the 64-bit IEEE 754 representation to reinterpret.

Return value

float

Errors

This call has no Err return slot. Its return type and documented sentinel values determine how to inspect the result.

float32_bits

float32_bits(x: float) -> int

Return the bit pattern after rounding to single precision.

Parameters

NameTypeDefaultDescription
xfloatRequiredNumeric input; direct trigonometric functions take radians.

Return value

int

Errors

This call has no Err return slot. Its return type and documented sentinel values determine how to inspect the result.

float32_from_bits

float32_from_bits(x: int) -> float

Construct a single-precision value from its bit pattern.

Parameters

NameTypeDefaultDescription
xintRequiredInteger carrying the 32-bit IEEE 754 representation to reinterpret.

Return value

float

Errors

This call has no Err return slot. Its return type and documented sentinel values determine how to inspect the result.

nan

nan() -> float

Return NaN.

Parameters

No parameters.

Return value

float

Errors

This call has no Err return slot. Its return type and documented sentinel values determine how to inspect the result.

inf

inf(sign: int) -> float

Return infinity with the selected sign.

Parameters

NameTypeDefaultDescription
signintRequiredSign selector or value from which the sign is copied.

Return value

float

Errors

This call has no Err return slot. Its return type and documented sentinel values determine how to inspect the result.

is_inf

is_inf(x: float, sign: int = 0) -> bool

Check for infinity with the selected sign.

Parameters

NameTypeDefaultDescription
xfloatRequiredNumeric input; direct trigonometric functions take radians.
signint0Sign selector or value from which the sign is copied.

Return value

bool

Errors

This call has no Err return slot. Its return type and documented sentinel values determine how to inspect the result.

is_nan

is_nan(x: float) -> bool

Check for NaN.

Parameters

NameTypeDefaultDescription
xfloatRequiredNumeric input; direct trigonometric functions take radians.

Return value

bool

Errors

This call has no Err return slot. Its return type and documented sentinel values determine how to inspect the result.

atan2

atan2(y: float, x: float) -> float

Provide functions using two or more values.

Parameters

NameTypeDefaultDescription
yfloatRequiredSecond operand; atan2 uses this as its vertical coordinate.
xfloatRequiredHorizontal coordinate; together with y it selects the quadrant.

Return value

float

Errors

This call has no Err return slot. Its return type and documented sentinel values determine how to inspect the result.

copysign

copysign(value: float, sign: float) -> float

Combine one value's magnitude with another's sign.

Parameters

NameTypeDefaultDescription
valuefloatRequiredValue to store, serialize, validate or pass to the operation described above.
signfloatRequiredSign selector or value from which the sign is copied.

Return value

float

Errors

This call has no Err return slot. Its return type and documented sentinel values determine how to inspect the result.

dim

dim(x: float, y: float) -> float

Return the positive difference of two values.

Parameters

NameTypeDefaultDescription
xfloatRequiredNumeric input; direct trigonometric functions take radians.
yfloatRequiredSecond operand; atan2 uses this as its vertical coordinate.

Return value

float

Errors

This call has no Err return slot. Its return type and documented sentinel values determine how to inspect the result.

fma

fma(x: float, y: float, z: float) -> float

Return a fused multiply-add with one rounding.

Parameters

NameTypeDefaultDescription
xfloatRequiredNumeric input; direct trigonometric functions take radians.
yfloatRequiredSecond operand; atan2 uses this as its vertical coordinate.
zfloatRequiredThird numeric operand added after the multiplication in fma.

Return value

float

Errors

This call has no Err return slot. Its return type and documented sentinel values determine how to inspect the result.

hypot

hypot(x: float, y: float) -> float

Return the hypotenuse length.

Parameters

NameTypeDefaultDescription
xfloatRequiredNumeric input; direct trigonometric functions take radians.
yfloatRequiredSecond operand; atan2 uses this as its vertical coordinate.

Return value

float

Errors

This call has no Err return slot. Its return type and documented sentinel values determine how to inspect the result.

ldexp

ldexp(frac: float, exp: int) -> float

Scale a fraction by a power of two.

Parameters

NameTypeDefaultDescription
fracfloatRequiredFractional value to scale by a power of two.
expintRequiredInteger exponent of two used to scale the fraction.

Return value

float

Errors

This call has no Err return slot. Its return type and documented sentinel values determine how to inspect the result.

max

max(x: float, y: float) -> float

Select the maximum with explicit NaN and signed-zero handling.

Parameters

NameTypeDefaultDescription
xfloatRequiredNumeric input; direct trigonometric functions take radians.
yfloatRequiredSecond operand; atan2 uses this as its vertical coordinate.

Return value

float

Errors

This call has no Err return slot. Its return type and documented sentinel values determine how to inspect the result.

min

min(x: float, y: float) -> float

Select the minimum with explicit NaN and signed-zero handling.

Parameters

NameTypeDefaultDescription
xfloatRequiredNumeric input; direct trigonometric functions take radians.
yfloatRequiredSecond operand; atan2 uses this as its vertical coordinate.

Return value

float

Errors

This call has no Err return slot. Its return type and documented sentinel values determine how to inspect the result.

mod

mod(x: float, y: float) -> float

Return the remainder after truncated division.

Parameters

NameTypeDefaultDescription
xfloatRequiredNumeric input; direct trigonometric functions take radians.
yfloatRequiredSecond operand; atan2 uses this as its vertical coordinate.

Return value

float

Errors

This call has no Err return slot. Its return type and documented sentinel values determine how to inspect the result.

nextafter

nextafter(x: float, y: float) -> float

Return the adjacent representable value toward the target.

Parameters

NameTypeDefaultDescription
xfloatRequiredNumeric input; direct trigonometric functions take radians.
yfloatRequiredSecond operand; atan2 uses this as its vertical coordinate.

Return value

float

Errors

This call has no Err return slot. Its return type and documented sentinel values determine how to inspect the result.

nextafter32

nextafter32(x: float, y: float) -> float

Return the adjacent single-precision value toward the target.

Parameters

NameTypeDefaultDescription
xfloatRequiredNumeric input; direct trigonometric functions take radians.
yfloatRequiredSecond operand; atan2 uses this as its vertical coordinate.

Return value

float

Errors

This call has no Err return slot. Its return type and documented sentinel values determine how to inspect the result.

pow

pow(x: float, y: float) -> float

Return a power.

Parameters

NameTypeDefaultDescription
xfloatRequiredNumeric input; direct trigonometric functions take radians.
yfloatRequiredSecond operand; atan2 uses this as its vertical coordinate.

Return value

float

Errors

This call has no Err return slot. Its return type and documented sentinel values determine how to inspect the result.

pow10

pow10(n: int) -> float

Return ten raised to an integral power.

Parameters

NameTypeDefaultDescription
nintRequiredInteger exponent in 10 raised to n.

Return value

float

Errors

This call has no Err return slot. Its return type and documented sentinel values determine how to inspect the result.

remainder

remainder(x: float, y: float) -> float

Return the remainder using the nearest integral quotient.

Parameters

NameTypeDefaultDescription
xfloatRequiredNumeric input; direct trigonometric functions take radians.
yfloatRequiredSecond operand; atan2 uses this as its vertical coordinate.

Return value

float

Errors

This call has no Err return slot. Its return type and documented sentinel values determine how to inspect the result.

frexp

frexp(x: float) -> Array

Return multiple results in declared order as an Array.

Parameters

NameTypeDefaultDescription
xfloatRequiredNumeric input; direct trigonometric functions take radians.

Return value

Array

Errors

This call has no Err return slot. Its return type and documented sentinel values determine how to inspect the result.

lgamma

lgamma(x: float) -> Array

Return log absolute Gamma and its sign.

Parameters

NameTypeDefaultDescription
xfloatRequiredNumeric input; direct trigonometric functions take radians.

Return value

Array

Errors

This call has no Err return slot. Its return type and documented sentinel values determine how to inspect the result.

modf

modf(x: float) -> Array

Split a value into integral and fractional parts.

Parameters

NameTypeDefaultDescription
xfloatRequiredNumeric input; direct trigonometric functions take radians.

Return value

Array

Errors

This call has no Err return slot. Its return type and documented sentinel values determine how to inspect the result.

sincos

sincos(x: float) -> Array

Return sine and cosine together.

Parameters

NameTypeDefaultDescription
xfloatRequiredNumeric input; direct trigonometric functions take radians.

Return value

Array

Errors

This call has no Err return slot. Its return type and documented sentinel values determine how to inspect the result.