unum

package module
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: May 30, 2025 License: GPL-3.0 Imports: 5 Imported by: 3

README

unum

This package provides number-related functions and some generic numeric types for Go.

Documentation.

License: GPL-3


Documentation

Overview

(TOC) This package provides number-related functions and some generic numeric types.

Index

Constants

This section is empty.

Variables

View Source
var Version string

Functions

func Clamp added in v1.0.1

func Clamp[N Number](minimum, value, maximum N) N

Clamp returns minimum if that's bigger than value; maximum if that's smaller than value; or value if it is in range [minimum, maximum]

func Commas

func Commas[I Integer](i I) string

func IsClose

func IsClose(a, b float64) bool

IsClose returns true if a and b are very close to each other. Should be adequate for test comparisons. See also IsZero. tag::IsClose[]

func IsZero

func IsZero(x float64) bool

IsZero returns true if x is close to 0. Should be adequate for test comparisons. See also IsClose. tag::IsZero[]

func MustStrToInt

func MustStrToInt(s string) int

func RoundToNearest

func RoundToNearest(f float64, nearestTo int) float64

func StrToInt

func StrToInt(s string, default_ int) int

Types

type Comparable

type Comparable interface {
	~string | ~int | ~int8 | ~int16 | ~int32 | ~int64 |
		~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64 | ~uintptr
}

Comparable allows only string or integer map keys or set elements.

type Integer

type Integer interface {
	~int | ~int8 | ~int16 | ~int32 | ~int64 |
		~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64 | ~uintptr
}

type Number

type Number interface {
	~float64 | ~float32 |
		~int | ~int8 | ~int16 | ~int32 | ~int64 |
		~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64
}

type SignedNumber

type SignedNumber interface {
	~float64 | ~float32 | ~int | ~int8 | ~int16 | ~int32 | ~int64
}

Jump to

Keyboard shortcuts

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