libm

package
v1.5.4 Latest Latest
Warning

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

Go to latest
Published: Dec 5, 2026 License: MIT Imports: 1 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

Overview

Package libm provides transcendental math functions whose results match Neo4j's correctly rounded Java Math functions more closely than Go's standard library math package.

The exponential, logarithmic and power functions (Exp, Exp2, Log, Log2, Pow) are ported from musl's math library, which in turn carries the Arm optimized-routines implementations (Copyright (c) 2018, Arm Limited, SPDX-License-Identifier: MIT). These are correctly rounded except in rare documented cases, whereas Go's math package (derived from fdlibm) can be up to 1 ulp away for inputs such as 3 ^ 2.5.

The hyperbolic functions (Sinh, Cosh, Tanh, Asinh, Acosh, Atanh) are ported from musl's wrappers over its correctly rounded Exp and Log.

Sin, Cos, Tan, Asin, Acos, Atan, Atan2 and Log10 are fdlibm-derived in both musl and Go's math package, so they are thin aliases to the corresponding math functions: musl's implementations are the Sun Microsystems fdlibm sources, which is the same origin as Go's math package.

See NOTICES.md for the full third-party licence texts.

Sinh is a Go port of musl's double-precision sinh function, Copyright (c) 2018, Arm Limited. SPDX-License-Identifier: MIT. See NOTICES.md for the licence text.

The hyperbolic functions below are thin wrappers over musl's correctly rounded Exp and Log, following the musl source line by line.

Index

Constants

View Source
const (
	E   = math.E
	Pi  = math.Pi
	Phi = math.Phi

	Sqrt2   = math.Sqrt2
	SqrtE   = math.SqrtE
	SqrtPi  = math.SqrtPi
	SqrtPhi = math.SqrtPhi

	Ln2    = math.Ln2
	Log2E  = math.Log2E
	Ln10   = math.Ln10
	Log10E = math.Log10E

	MaxFloat64             = math.MaxFloat64
	SmallestNonzeroFloat64 = math.SmallestNonzeroFloat64

	MaxInt8   = math.MaxInt8
	MinInt8   = math.MinInt8
	MaxInt16  = math.MaxInt16
	MinInt16  = math.MinInt16
	MaxInt32  = math.MaxInt32
	MinInt32  = math.MinInt32
	MaxInt64  = math.MaxInt64
	MinInt64  = math.MinInt64
	MaxUint8  = math.MaxUint8
	MaxUint16 = math.MaxUint16
	MaxUint32 = math.MaxUint32
	MaxUint64 = math.MaxUint64
	MaxUint   = math.MaxUint
)

Variables

This section is empty.

Functions

func Abs

func Abs(x float64) float64

Exact and trivial functions: re-exported from the standard library. These are correctly rounded (or exact) by construction, so they never differ from Neo4j's results.

func Acos

func Acos(x float64) float64

Acos returns the arccosine of x, in radians.

func Acosh

func Acosh(x float64) float64

Acosh returns the inverse hyperbolic cosine of x.

func Asin

func Asin(x float64) float64

Asin returns the arcsine of x, in radians.

func Asinh

func Asinh(x float64) float64

Asinh returns the inverse hyperbolic sine of x.

func Atan

func Atan(x float64) float64

Atan returns the arctangent of x, in radians.

func Atan2

func Atan2(y, x float64) float64

Atan2 returns the arctangent of y/x, using the signs of both to pick the quadrant.

func Atanh

func Atanh(x float64) float64

Atanh returns the inverse hyperbolic tangent of x.

func Ceil

func Ceil(x float64) float64

func Copysign

func Copysign(x, y float64) float64

func Cos

func Cos(x float64) float64

Cos returns the cosine of x (radians).

func Cosh

func Cosh(x float64) float64

Cosh returns the hyperbolic cosine of x.

func Exp

func Exp(x float64) float64

Exp returns e**x, the base-e exponential of x.

func Exp2

func Exp2(x float64) float64

Exp2 returns 2**x, the base-2 exponential of x.

func Expm1

func Expm1(x float64) float64

func Float32bits

func Float32bits(f float32) uint32

func Float32frombits

func Float32frombits(b uint32) float32

func Float64bits

func Float64bits(f float64) uint64

func Float64frombits

func Float64frombits(b uint64) float64

func Floor

func Floor(x float64) float64

func Frexp

func Frexp(f float64) (frac float64, exp int)

func Inf

func Inf(sign int) float64

func IsInf

func IsInf(x float64, sign int) bool

func IsNaN

func IsNaN(x float64) bool

func Ldexp

func Ldexp(frac float64, exp int) float64

func Log

func Log(x float64) float64

Log returns the natural logarithm of x.

func Log1p

func Log1p(x float64) float64

Log1p and Expm1 are re-exported from the standard library. Sin, Cos, Tan, Asin, Acos, Atan, Atan2 and Log10 are ported from musl (trig.go, invtrig.go): Go's sin, cos, tan and atan come from Cephes, not fdlibm, and differed from Neo4j's results for a quarter to a third of inputs (#907).

func Log2

func Log2(x float64) float64

Log2 returns the binary logarithm of x.

func Log10

func Log10(x float64) float64

Log10 returns the decimal logarithm of x.

func Max

func Max(x, y float64) float64

func Min

func Min(x, y float64) float64

func Mod

func Mod(x, y float64) float64

func Modf

func Modf(f float64) (int, frac float64)

func NaN

func NaN() float64

func Pow

func Pow(x, y float64) float64

Pow returns x**y, the base-x exponential of y.

func Pow10

func Pow10(n int) float64

func Round

func Round(x float64) float64

func RoundToEven

func RoundToEven(x float64) float64

func Signbit

func Signbit(x float64) bool

func Sin

func Sin(x float64) float64

Sin returns the sine of x (radians).

func Sinh

func Sinh(x float64) float64

Sinh returns the hyperbolic sine of x.

func Sqrt

func Sqrt(x float64) float64

func Tan

func Tan(x float64) float64

Tan returns the tangent of x (radians).

func Tanh

func Tanh(x float64) float64

Tanh returns the hyperbolic tangent of x.

func Trunc

func Trunc(x float64) float64

Types

This section is empty.

Jump to

Keyboard shortcuts

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