math

package
v1.1.2 Latest Latest
Warning

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

Go to latest
Published: May 26, 2026 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Package math provides APOC mathematical functions.

This package implements all apoc.math.* functions for mathematical operations in Cypher queries.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Abs

func Abs(value float64) float64

Abs returns the absolute value.

Example:

apoc.math.abs(-5.5) => 5.5

func Acos

func Acos(value float64) float64

Acos returns the arccosine (in radians).

Example:

apoc.math.acos(1) => 0.0

func Asin

func Asin(value float64) float64

Asin returns the arcsine (in radians).

Example:

apoc.math.asin(1) => math.Pi / 2

func Atan

func Atan(value float64) float64

Atan returns the arctangent (in radians).

Example:

apoc.math.atan(1) => math.Pi / 4

func Atan2

func Atan2(y, x float64) float64

Atan2 returns the arctangent of y/x (in radians).

Example:

apoc.math.atan2(1, 1) => math.Pi / 4

func Ceil

func Ceil(value float64) float64

Ceil rounds up to the nearest integer.

Example:

apoc.math.ceil(3.14) => 4.0

func Clamp

func Clamp(value, min, max float64) float64

Clamp restricts a value to a range.

Example:

apoc.math.clamp(15, 0, 10) => 10
apoc.math.clamp(-5, 0, 10) => 0
apoc.math.clamp(5, 0, 10) => 5

func Cos

func Cos(angle float64) float64

Cos returns the cosine of an angle (in radians).

Example:

apoc.math.cos(0) => 1.0

func Cosh

func Cosh(value float64) float64

Cosh returns the hyperbolic cosine.

Example:

apoc.math.cosh(0) => 1.0

func Exp

func Exp(value float64) float64

Exp returns e raised to the power of x.

Example:

apoc.math.exp(1) => 2.718281828...

func Factorial

func Factorial(n int64) int64

Factorial returns the factorial of n.

Example:

apoc.math.factorial(5) => 120

func Fibonacci

func Fibonacci(n int64) int64

Fibonacci returns the nth Fibonacci number.

Example:

apoc.math.fibonacci(10) => 55

func Floor

func Floor(value float64) float64

Floor rounds down to the nearest integer.

Example:

apoc.math.floor(3.14) => 3.0

func Gcd

func Gcd(a, b int64) int64

Gcd returns the greatest common divisor.

Example:

apoc.math.gcd(48, 18) => 6

func IsPrime

func IsPrime(n int64) bool

IsPrime checks if a number is prime.

Example:

apoc.math.isPrime(17) => true
apoc.math.isPrime(18) => false

func Lcm

func Lcm(a, b int64) int64

Lcm returns the least common multiple.

Example:

apoc.math.lcm(12, 18) => 36

func Lerp

func Lerp(start, end, t float64) float64

Lerp performs linear interpolation between two values.

Example:

apoc.math.lerp(0, 10, 0.5) => 5.0
apoc.math.lerp(0, 10, 0.25) => 2.5

func Log

func Log(value float64) float64

Log returns the natural logarithm.

Example:

apoc.math.log(math.E) => 1.0

func Log10

func Log10(value float64) float64

Log10 returns the base-10 logarithm.

Example:

apoc.math.log10(100) => 2.0

func Logit

func Logit(value float64) float64

Logit returns the logit function (inverse of sigmoid).

Example:

apoc.math.logit(0.5) => 0.0

func MaxDouble

func MaxDouble(values ...float64) float64

MaxDouble returns the maximum of multiple floats.

Example:

apoc.math.maxDouble(5.5, 2.3, 8.1, 1.9) => 8.1

func MaxLong

func MaxLong(values ...int64) int64

MaxLong returns the maximum of multiple integers.

Example:

apoc.math.maxLong(5, 2, 8, 1, 9) => 9

func Mean

func Mean(values []float64) float64

Mean returns the arithmetic mean of a list.

Example:

apoc.math.mean([1,2,3,4,5]) => 3.0

func Median

func Median(values []float64) float64

Median returns the median value of a list.

Example:

apoc.math.median([1,2,3,4,5]) => 3.0

func MinDouble

func MinDouble(values ...float64) float64

MinDouble returns the minimum of multiple floats.

Example:

apoc.math.minDouble(5.5, 2.3, 8.1, 1.9) => 1.9

func MinLong

func MinLong(values ...int64) int64

MinLong returns the minimum of multiple integers.

Example:

apoc.math.minLong(5, 2, 8, 1, 9) => 1

func Mode

func Mode(values []float64) float64

Mode returns the most frequent value in a list.

Example:

apoc.math.mode([1,2,2,3,3,3,4]) => 3.0

func NextPrime

func NextPrime(n int64) int64

NextPrime returns the next prime number after n.

Example:

apoc.math.nextPrime(10) => 11

func Normalize

func Normalize(value, oldMin, oldMax, newMin, newMax float64) float64

Normalize normalizes a value from one range to another.

Example:

apoc.math.normalize(5, 0, 10, 0, 1) => 0.5

func Percentile

func Percentile(values []float64, percentile float64) float64

Percentile calculates the nth percentile of a list.

Example:

apoc.math.percentile([1,2,3,4,5,6,7,8,9,10], 50) => 5.5

func Pow

func Pow(base, exponent float64) float64

Pow raises a number to a power.

Example:

apoc.math.pow(2, 8) => 256.0

func Product

func Product(values []float64) float64

Product returns the product of a list of numbers.

Example:

apoc.math.product([2,3,4]) => 24.0

func Random

func Random() float64

Random returns a random float between 0 and 1.

Example:

apoc.math.random() => 0.7234... (random)

func RandomInt

func RandomInt(min, max int64) int64

RandomInt returns a random integer in a range [min, max].

Example:

apoc.math.randomInt(1, 10) => 7 (random)

func Range

func Range(start, end, step int64) []int64

Range returns a list of numbers from start to end.

Example:

apoc.math.range(1, 5) => [1,2,3,4,5]

func Round

func Round(value float64, precision int) float64

Round rounds a number to a given precision.

Example:

apoc.math.round(3.14159, 2) => 3.14
apoc.math.round(1234.5, -2) => 1200.0

func Sigmoid

func Sigmoid(value float64) float64

Sigmoid returns the sigmoid function value.

Example:

apoc.math.sigmoid(0) => 0.5

func Sin

func Sin(angle float64) float64

Sin returns the sine of an angle (in radians).

Example:

apoc.math.sin(math.Pi / 2) => 1.0

func Sinh

func Sinh(value float64) float64

Sinh returns the hyperbolic sine.

Example:

apoc.math.sinh(0) => 0.0

func Sqrt

func Sqrt(value float64) float64

Sqrt returns the square root.

Example:

apoc.math.sqrt(16) => 4.0

func StdDev

func StdDev(values []float64) float64

StdDev returns the standard deviation of a list.

Example:

apoc.math.stdDev([2,4,4,4,5,5,7,9]) => 2.0

func Sum

func Sum(values []float64) float64

Sum returns the sum of a list of numbers.

Example:

apoc.math.sum([1,2,3,4,5]) => 15.0

func Tan

func Tan(angle float64) float64

Tan returns the tangent of an angle (in radians).

Example:

apoc.math.tan(math.Pi / 4) => 1.0

func Tanh

func Tanh(value float64) float64

Tanh returns the hyperbolic tangent.

Example:

apoc.math.tanh(0) => 0.0

func Variance

func Variance(values []float64) float64

Variance returns the variance of a list.

Example:

apoc.math.variance([2,4,4,4,5,5,7,9]) => 4.0

Types

This section is empty.

Jump to

Keyboard shortcuts

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