math

package
v2.0.0-alpha.63 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 27, 2026 License: Apache-2.0 Imports: 7 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
const (
	RadToDeg  = 180 / math.Pi
	DegToRad  = math.Pi / 180
	RadToGrad = 200 / math.Pi
	GradToDeg = math.Pi / 200
)

Variables

This section is empty.

Functions

func Abs

abs returns the absolute value of a given number. @param number {Int | Float} Input number. @return {Float} The absolute value of a given number.

func Acos

func Acos(_ context.Context, arg runtime.Value) (runtime.Value, error)

acos returns the arccosine, in radians, of a given number. @param number {Int | Float} Input number. @return {Float} The arccosine, in radians, of a given number.

func Asin

func Asin(_ context.Context, arg runtime.Value) (runtime.Value, error)

asin returns the arcsine, in radians, of a given number. @param number {Int | Float} Input number. @return {Float} The arcsine, in radians, of a given number.

func Atan

func Atan(_ context.Context, arg runtime.Value) (runtime.Value, error)

atan returns the arctangent, in radians, of a given number. @param number {Int | Float} Input number. @return {Float} The arctangent, in radians, of a given number.

func Atan2

func Atan2(_ context.Context, arg1, arg2 runtime.Value) (runtime.Value, error)

atan2 returns the arc tangent of y/x, using the signs of the two to determine the quadrant of the return value. @param number1 {Int | Float} Input number. @param number2 {Int | Float} Input number. @return {Float} The arc tangent of y/x, using the signs of the two to determine the quadrant of the return value.

func Average

func Average(ctx context.Context, arg runtime.Value) (runtime.Value, error)

average returns the arithmetic mean of the numeric elements in a list. @param array {Any[]} A list whose Int and Float elements are used; other elements are ignored. It is not mutated. @return {Float} The arithmetic mean, or zero when no numbers remain. @throws {TypeError} An argument has an invalid type. @deprecated Use math::mean instead.

func Cbrt

func Cbrt(_ context.Context, value runtime.Value) (runtime.Value, error)

cbrt returns the real cube root of a number, including negative numbers. @param value {Int | Float} Input number. @return {Float} The cube root, preserving NaN, infinities, and signed zero. @throws {TypeError} The argument is not numeric.

func Ceil

func Ceil(_ context.Context, arg runtime.Value) (runtime.Value, error)

ceil returns the least integer value greater than or equal to a given value. @param number {Int | Float} Input number. @return {Int} The least integer value greater than or equal to a given value. @throws {RangeError} The rounded result is not a finite signed 64-bit integer.

func Clamp

func Clamp(ctx context.Context, value, min, max runtime.Value) (runtime.Value, error)

clamp limits a number to the inclusive interval from min to max. @param value {Int | Float} Input number. @param min {Int | Float} Lower bound; must not be NaN or greater than max. @param max {Int | Float} Upper bound; must not be NaN. Infinite bounds are allowed. @return {Int | Float} The original min if value is below it, max if above it, or value otherwise. Equality and NaN preserve value unchanged. @throws {TypeError} An argument is not numeric. @throws {InvalidArgument} A bound is NaN or min is greater than max.

func Cos

cos returns the cosine of a given number. @param number {Int | Float} Input number. @return {Float} The cosine of a given number.

func Degrees

func Degrees(_ context.Context, arg runtime.Value) (runtime.Value, error)

degrees returns the angle converted from radians to degrees. @param number {Int | Float} The input number. @return {Float} The angle in degrees

func E

e returns Euler's number, the base of the natural logarithm. @return {Float} Euler's number, approximately 2.718281828459045.

func Exp

exp returns Euler's constant (2.71828...) raised to the power of value. @param number {Int | Float} Input number. @return {Float} Euler's constant raised to the power of value.

func Exp2

func Exp2(_ context.Context, arg runtime.Value) (runtime.Value, error)

exp2 returns 2 raised to the power of value. @param number {Int | Float} Input number. @return {Float} 2 raised to the power of value.

func Expm1

func Expm1(_ context.Context, value runtime.Value) (runtime.Value, error)

expm1 computes exp(value)-1 with improved numerical accuracy for values near zero. @param value {Int | Float} Input number. @return {Float} The exponential minus one; negative infinity gives -1, while NaN, positive infinity, and signed zero are preserved. @throws {TypeError} The argument is not numeric.

func Floor

func Floor(_ context.Context, arg runtime.Value) (runtime.Value, error)

floor returns the greatest integer value less than or equal to a given value. @param number {Int | Float} Input number. @return {Int} The greatest integer value less than or equal to a given value. @throws {RangeError} The rounded result is not a finite signed 64-bit integer.

func Hypot

func Hypot(_ context.Context, x, y runtime.Value) (runtime.Value, error)

hypot computes sqrt(x*x + y*y), avoiding unnecessary overflow and underflow. @param x {Int | Float} First coordinate. @param y {Int | Float} Second coordinate. @return {Float} The nonnegative distance; infinity takes precedence over NaN. @throws {TypeError} An argument is not numeric.

func Log

log returns the natural logarithm of a given value. @param number {Int | Float} Input number. @return {Float} The natural logarithm of a given value.

func Log1p

func Log1p(_ context.Context, value runtime.Value) (runtime.Value, error)

log1p computes ln(1+value) with improved numerical accuracy for values near zero. @param value {Int | Float} Input number. @return {Float} The logarithm; -1 gives negative infinity, values below -1 give NaN, and signed zero is preserved. @throws {TypeError} The argument is not numeric.

func Log2

func Log2(_ context.Context, arg runtime.Value) (runtime.Value, error)

log2 returns the binary logarithm of a given value. @param number {Int | Float} Input number. @return {Float} The binary logarithm of a given value.

func Log10

func Log10(_ context.Context, arg runtime.Value) (runtime.Value, error)

log10 returns the decimal logarithm of a given value. @param number {Int | Float} Input number. @return {Float} The decimal logarithm of a given value.

func Max

func Max(ctx context.Context, arg runtime.Value) (runtime.Value, error)

max returns the largest number among the numeric elements in a list. @param array {Any[]} A list whose Int and Float elements are used; other elements are ignored. It is not mutated. @return {Float | None} The largest number as Float, or None when no numbers remain. @throws {TypeError} An argument has an invalid type. @deprecated Use math::max instead.

func Median

func Median(ctx context.Context, arg runtime.Value) (runtime.Value, error)

median returns the middle numeric value, averaging the two middle numbers for even numeric counts. @param array {Any[]} A list whose Int and Float elements are used; other elements are ignored. It is not mutated. @return {Int | Float | None} The selected middle value or their Float mean, or None when no numbers remain. @throws {TypeError} An argument has an invalid type. @deprecated Use math::median instead.

func Min

func Min(ctx context.Context, arg runtime.Value) (runtime.Value, error)

min returns the smallest number among the numeric elements in a list. @param array {Any[]} A list whose Int and Float elements are used; other elements are ignored. It is not mutated. @return {Float | None} The smallest number as Float, or None when no numbers remain. @throws {TypeError} An argument has an invalid type. @deprecated Use math::min instead.

func Percentile

func Percentile(ctx context.Context, args ...runtime.Value) (runtime.Value, error)

percentile returns the nth percentile of the values in a given array. @param array {Any[]} A list whose Int and Float elements are used; other elements are ignored. It is not mutated. @param number {Int} A number which must be between 0 (excluded) and 100 (included). @param method {String} "interpolation" uses linear interpolation; all other strings select nearest rank. @return {Int | Float} The selected number or interpolated Float, or NaN when no numbers remain. @throws {TypeError} An argument has an invalid type. @deprecated Use math::percentile instead.

func Pi

pi returns Pi value. @return {Float} Pi value.

func PopulationVariance

func PopulationVariance(ctx context.Context, arg runtime.Value) (runtime.Value, error)

variance_population returns the population variance, dividing squared deviations from the mean by the numeric count N. @param numbers {Any[]} A list whose Int and Float elements are used; other elements are ignored. It is not mutated. @return {Float} The population variance, or NaN when no numbers remain. @throws {TypeError} An argument has an invalid type. @deprecated Use math::variance instead.

func Pow

func Pow(_ context.Context, arg1, arg2 runtime.Value) (runtime.Value, error)

pow returns the base to the exponent value. @param base {Int | Float} The base value. @param exp {Int | Float} The exponent value. @return {Float} The exponentiated value.

func Radians

func Radians(_ context.Context, arg runtime.Value) (runtime.Value, error)

radians returns the angle converted from degrees to radians. @param number {Int | Float} The input number. @return {Float} The angle in radians.

func Rand

func Rand(ctx context.Context, args ...runtime.Value) (runtime.Value, error)

Rand preserves the legacy zero-, one-, and two-argument random calculations using the Session source transported by ctx. Deprecated: Use random.Float, random.Int, or random.Bool with an execution context.

func Range

func Range(ctx context.Context, args ...runtime.Value) (runtime.Value, error)

range returns an array of numbers in the specified range, optionally with increments other than 1. @param start {Int | Float} The value to start the range at (inclusive). @param end {Int | Float} The value to end the range with (inclusive). @param step {Int | Float} How much to change the value in every step. Positive steps ascend, negative steps descend, and zero is invalid. @return {Float[]} Numbers in the inclusive range, using a default step of one. @deprecated Use arrays::range instead.

func RegisterLib

func RegisterLib(ns runtime.Namespace)

RegisterLib registers canonical math functions and deprecated global compatibility functions. @namespace math

func Round

func Round(_ context.Context, arg runtime.Value) (runtime.Value, error)

round returns the nearest integer, rounding half away from zero. @param number {Int | Float} Input number. @return {Int} The nearest integer, rounding half away from zero. @throws {RangeError} The rounded result is not a finite signed 64-bit integer.

func SampleVariance

func SampleVariance(ctx context.Context, arg runtime.Value) (runtime.Value, error)

variance_sample returns the sample variance, dividing squared deviations from the mean by the numeric count N minus one. @param numbers {Any[]} A list whose Int and Float elements are used; other elements are ignored. It is not mutated. @return {Float} The sample variance, or NaN for fewer than two numbers. @throws {TypeError} An argument has an invalid type. @deprecated Use math::variance_sample instead.

func Sign

func Sign(_ context.Context, value runtime.Value) (runtime.Value, error)

sign returns the sign of a number, including positive and negative infinity. @param value {Int | Float} Input number; must not be NaN. @return {Int} Minus one for negative values, zero for either signed zero, or one for positive values. @throws {TypeError} The argument is not numeric. @throws {InvalidArgument} The argument is NaN and has no ordered sign.

func Sin

sin returns the sine of the radian argument. @param number {Int | Float} Input number. @return {Float} The sin, in radians, of a given number.

func Sqrt

func Sqrt(_ context.Context, arg runtime.Value) (runtime.Value, error)

sqrt returns the square root of a given number. @param value {Int | Float} A number. @return {Float} The square root.

func StandardDeviationPopulation

func StandardDeviationPopulation(ctx context.Context, arg runtime.Value) (runtime.Value, error)

stddev_population returns the square root of the population variance. @param numbers {Any[]} A list whose Int and Float elements are used; other elements are ignored. It is not mutated. @return {Float} The population standard deviation, or NaN when no numbers remain. @throws {TypeError} An argument has an invalid type. @deprecated Use math::stddev instead.

func StandardDeviationSample

func StandardDeviationSample(ctx context.Context, arg runtime.Value) (runtime.Value, error)

stddev_sample returns the square root of the sample variance. @param numbers {Any[]} A list whose Int and Float elements are used; other elements are ignored. It is not mutated. @return {Float} The sample standard deviation, or NaN for fewer than two numbers. @throws {TypeError} An argument has an invalid type. @deprecated Use math::stddev_sample instead.

func Sum

func Sum(ctx context.Context, arg runtime.Value) (runtime.Value, error)

sum returns the sum of the numeric elements in a list. @param numbers {Any[]} A list whose Int and Float elements are used; other elements are ignored. It is not mutated. @return {Int | Float} The sum as Float, including zero when all elements are ignored; integer zero for an empty list. @throws {TypeError} An argument has an invalid type. @deprecated Use math::sum instead.

func Tan

tan returns the tangent of a given number. @param number {Int | Float} A number. @return {Float} The tangent.

func Trunc

func Trunc(_ context.Context, value runtime.Value) (runtime.Value, error)

trunc removes the fractional part of a number by rounding toward zero. @param value {Int | Float} Input number. @return {Int | Float} The input Int unchanged, or a truncated Float preserving NaN, infinities, and signed zero. @throws {TypeError} The argument is not numeric.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL