API reference
GD.math
Entry for standard mathematical functions, IEEE 754 special values, and bit conversions.
Properties
bits: GD.math.bitsInteger math entry for uint64 bit counts, rotations, reversals, and operations with carry.
e: floatpi: floatphi: floatsqrt2: floatsqrt_e: floatsqrt_pi: floatsqrt_phi: floatln2: floatlog2_e: floatln10: floatlog10_e: floatmax_float64: floatsmallest_nonzero_float64: float
Methods
abs(x: float) -> floatacos(x: float) -> floatacosh(x: float) -> floatasin(x: float) -> floatasinh(x: float) -> floatatan(x: float) -> floatatanh(x: float) -> floatcbrt(x: float) -> floatceil(x: float) -> floatcos(x: float) -> floatcosh(x: float) -> floaterf(x: float) -> floaterfc(x: float) -> floaterfinv(x: float) -> floaterfcinv(x: float) -> floatexp(x: float) -> floatexp2(x: float) -> floatexpm1(x: float) -> floatfloor(x: float) -> floatgamma(x: float) -> floatilogb(x: float) -> intj0(x: float) -> floatj1(x: float) -> floatlog(x: float) -> floatlog1p(x: float) -> floatlog2(x: float) -> floatlog10(x: float) -> floatlogb(x: float) -> floatround(x: float) -> floatround_to_even(x: float) -> floatsignbit(x: float) -> boolsin(x: float) -> floatsinh(x: float) -> floatsqrt(x: float) -> floattan(x: float) -> floattanh(x: float) -> floattrunc(x: float) -> floaty0(x: float) -> floaty1(x: float) -> floatfloat64_bits(x: float) -> intfloat64_from_bits(x: int) -> floatfloat32_bits(x: float) -> intfloat32_from_bits(x: int) -> floatnan() -> floatinf(sign: int) -> floatis_inf(x: float, sign: int = 0) -> boolis_nan(x: float) -> boolatan2(y: float, x: float) -> floatcopysign(value: float, sign: float) -> floatdim(x: float, y: float) -> floatfma(x: float, y: float, z: float) -> floathypot(x: float, y: float) -> floatldexp(frac: float, exp: int) -> floatmax(x: float, y: float) -> floatmin(x: float, y: float) -> floatmod(x: float, y: float) -> floatnextafter(x: float, y: float) -> floatnextafter32(x: float, y: float) -> floatpow(x: float, y: float) -> floatpow10(n: int) -> floatremainder(x: float, y: float) -> floatfrexp(x: float) -> Arraylgamma(x: float) -> Arraymodf(x: float) -> Arraysincos(x: float) -> Array
abs
abs(x: float) -> floatProvide unary mathematical functions.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
x | float | Required | Numeric 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) -> floatReturn inverse cosine.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
x | float | Required | Numeric 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) -> floatReturn inverse hyperbolic cosine.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
x | float | Required | Numeric 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) -> floatReturn inverse sine.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
x | float | Required | Numeric 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) -> floatReturn inverse hyperbolic sine.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
x | float | Required | Numeric 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) -> floatReturn inverse tangent.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
x | float | Required | Numeric 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) -> floatReturn inverse hyperbolic tangent.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
x | float | Required | Numeric 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) -> floatReturn cube root.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
x | float | Required | Numeric 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) -> floatRound toward positive infinity.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
x | float | Required | Numeric 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) -> floatReturn cosine.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
x | float | Required | Numeric 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) -> floatReturn hyperbolic cosine.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
x | float | Required | Numeric 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) -> floatReturn the error function.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
x | float | Required | Numeric 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) -> floatReturn the complementary error function.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
x | float | Required | Numeric 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) -> floatReturn inverse error function.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
x | float | Required | Numeric 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) -> floatReturn inverse complementary error function.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
x | float | Required | Numeric 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) -> floatReturn the natural exponential.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
x | float | Required | Numeric 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) -> floatReturn the base-two exponential.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
x | float | Required | Numeric 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) -> floatReturn the natural exponential minus one.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
x | float | Required | Numeric 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) -> floatRound toward negative infinity.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
x | float | Required | Numeric 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) -> floatReturn the Gamma function.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
x | float | Required | Numeric 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) -> intReturn the binary exponent as an integer.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
x | float | Required | Numeric 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) -> floatNormalize platform C-math Bessel functions to the public contract.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
x | float | Required | Numeric 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) -> floatReturn the first-kind Bessel function of order one.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
x | float | Required | Numeric 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) -> floatReturn the natural logarithm.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
x | float | Required | Numeric 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) -> floatReturn the natural logarithm of one plus the input.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
x | float | Required | Numeric 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) -> floatReturn the base-two logarithm.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
x | float | Required | Numeric 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) -> floatReturn the base-ten logarithm.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
x | float | Required | Numeric 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) -> floatReturn the binary exponent as a floating-point value.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
x | float | Required | Numeric 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) -> floatRound to the nearest integer with ties away from zero.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
x | float | Required | Numeric 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) -> floatRound ties to even, preserving signed zero and large integral values.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
x | float | Required | Numeric 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) -> boolReport whether the sign bit is set.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
x | float | Required | Numeric 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) -> floatReturn sine.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
x | float | Required | Numeric 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) -> floatReturn hyperbolic sine.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
x | float | Required | Numeric 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) -> floatReturn square root.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
x | float | Required | Numeric 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) -> floatReturn tangent.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
x | float | Required | Numeric 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) -> floatReturn hyperbolic tangent.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
x | float | Required | Numeric 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) -> floatTruncate the fractional part toward zero.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
x | float | Required | Numeric 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) -> floatReturn the second-kind Bessel function of order zero.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
x | float | Required | Numeric 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) -> floatReturn the second-kind Bessel function of order one.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
x | float | Required | Numeric 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) -> intConvert between floating-point values and IEEE 754 integer bit patterns.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
x | float | Required | Numeric 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) -> floatConstruct a double from its bit pattern.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
x | int | Required | Integer 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) -> intReturn the bit pattern after rounding to single precision.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
x | float | Required | Numeric 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) -> floatConstruct a single-precision value from its bit pattern.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
x | int | Required | Integer 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() -> floatReturn 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) -> floatReturn infinity with the selected sign.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
sign | int | Required | Sign 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) -> boolCheck for infinity with the selected sign.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
x | float | Required | Numeric input; direct trigonometric functions take radians. |
sign | int | 0 | Sign 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) -> boolCheck for NaN.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
x | float | Required | Numeric 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) -> floatProvide functions using two or more values.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
y | float | Required | Second operand; atan2 uses this as its vertical coordinate. |
x | float | Required | Horizontal 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) -> floatCombine one value's magnitude with another's sign.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
value | float | Required | Value to store, serialize, validate or pass to the operation described above. |
sign | float | Required | Sign 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) -> floatReturn the positive difference of two values.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
x | float | Required | Numeric input; direct trigonometric functions take radians. |
y | float | Required | Second 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) -> floatReturn a fused multiply-add with one rounding.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
x | float | Required | Numeric input; direct trigonometric functions take radians. |
y | float | Required | Second operand; atan2 uses this as its vertical coordinate. |
z | float | Required | Third 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) -> floatReturn the hypotenuse length.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
x | float | Required | Numeric input; direct trigonometric functions take radians. |
y | float | Required | Second 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) -> floatScale a fraction by a power of two.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
frac | float | Required | Fractional value to scale by a power of two. |
exp | int | Required | Integer 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) -> floatSelect the maximum with explicit NaN and signed-zero handling.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
x | float | Required | Numeric input; direct trigonometric functions take radians. |
y | float | Required | Second 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) -> floatSelect the minimum with explicit NaN and signed-zero handling.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
x | float | Required | Numeric input; direct trigonometric functions take radians. |
y | float | Required | Second 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) -> floatReturn the remainder after truncated division.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
x | float | Required | Numeric input; direct trigonometric functions take radians. |
y | float | Required | Second 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) -> floatReturn the adjacent representable value toward the target.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
x | float | Required | Numeric input; direct trigonometric functions take radians. |
y | float | Required | Second 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) -> floatReturn the adjacent single-precision value toward the target.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
x | float | Required | Numeric input; direct trigonometric functions take radians. |
y | float | Required | Second 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) -> floatReturn a power.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
x | float | Required | Numeric input; direct trigonometric functions take radians. |
y | float | Required | Second 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) -> floatReturn ten raised to an integral power.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
n | int | Required | Integer 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) -> floatReturn the remainder using the nearest integral quotient.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
x | float | Required | Numeric input; direct trigonometric functions take radians. |
y | float | Required | Second 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) -> ArrayReturn multiple results in declared order as an Array.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
x | float | Required | Numeric 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) -> ArrayReturn log absolute Gamma and its sign.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
x | float | Required | Numeric 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) -> ArraySplit a value into integral and fractional parts.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
x | float | Required | Numeric 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) -> ArrayReturn sine and cosine together.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
x | float | Required | Numeric 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.