math

package
v0.1.4 Latest Latest
Warning

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

Go to latest
Published: Aug 13, 2026 License: BSD-3-Clause Imports: 4 Imported by: 0

Documentation

Overview

Package math provides safe integer conversions with overflow protection.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Clamp

func Clamp(v, lower, upper float64) float64

Clamp restricts a value to a range [lower, upper]. If v < lower, returns lower. If v > upper, returns upper. Otherwise, returns v.

func MustSafeIntToUint32

func MustSafeIntToUint32(i int) uint32

MustSafeIntToUint32 invokes SafeIntToUint32 and panics if an error is returned.

func MustSafeUint64ToInt64

func MustSafeUint64ToInt64(u uint64) int64

MustSafeUint64ToInt64 invokes SafeUint64ToInt64 and panics if an error is returned.

func SafeAddUint64Ptr

func SafeAddUint64Ptr(counter *uint64, values ...int) error

SafeAddUint64Ptr adds the values to the counter pointer, and returns an error if the counter would overflow.

func SafeIntToUint32

func SafeIntToUint32(i int) (uint32, error)

SafeIntToUint32 converts an int to a uint32, returning an error if the value is negative or exceeds the maximum uint32 value.

func SafeUint64ToInt64

func SafeUint64ToInt64(u uint64) (int64, error)

SafeUint64ToInt64 converts a uint64 to an int64, returning an error if the value is too large to fit in an int64.

Types

This section is empty.

Jump to

Keyboard shortcuts

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