math

package
v1.0.6 Latest Latest
Warning

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

Go to latest
Published: Feb 10, 2026 License: MIT Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AbsI64

func AbsI64(val int64) int64

Return the absolute value of a 64-bit signed integer value.

func ClampI64

func ClampI64(val, minVal, maxVal int64) int64

Clamp a signed 64-bit value to a minima and maxima.

func FormatFloat64

func FormatFloat64(num float64) string

Format a float.

If the float is NaN or infinite, then those are explicitly returned.

func MaxI

func MaxI(lhs, rhs int) int

Return the maximum value of the integer values.

func MaxI32

func MaxI32(lhs, rhs int32) int32

Return the maximum value of the 32-bit integer values.

func MaxI64

func MaxI64(lhs, rhs int64) int64

Return the maximum value of the 64-bit integer values.

func MinI

func MinI(lhs, rhs int) int

Return the minimum value of the integer values.

func MinI32

func MinI32(lhs, rhs int32) int32

Return the minimum value of the 32-bit integer values.

func MinI64

func MinI64(lhs, rhs int64) int64

Return the minimum value of the 64-bit integer values.

func RoundF

func RoundF(num float64, precision uint) float64

Rounds num to the given number of decimal places and returns the result as a float64, using math.Round for IEEE-754 compliant rounding.

func RoundI

func RoundI(num float64) int

Rounds a 64-bit floating point number to the nearest integer, returning it as an int. Values halfway between integers are rounded away from zero.

func ToFixed

func ToFixed(num float64, precision uint) float64

Rounds num to the given number of decimal places and returns the result as a float64. Unlike RoundF, it uses integer rounding logic (via RoundI), which may behave slightly differently around half-values.

func WithinPlatform

func WithinPlatform(value, defValue int64) int

Ensure that the given value is within the limit of the platform-specific integer type and, if it is, multiply it by two.

If the value would be larger than the platform integer, then the default value in `defValue` is returned.

If `defValue` is too large, then the maximum integer size for the platform is returned.

Types

This section is empty.

Jump to

Keyboard shortcuts

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