ordered

package
v0.20.1 Latest Latest
Warning

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

Go to latest
Published: Oct 29, 2025 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Package ordered contains generic utility functions over ordered types, i.e. types that support the operators <, >, == etc.

Index

Constants

This section is empty.

Variables

View Source
var ErrEmptySlice = errors.New("no elements in slice")
View Source
var ErrUnknownType = errors.New("uknown type")

Functions

func Abs

func Abs[T Real](n T) T

Abs returns the absolute value of a non-complex numeric type

func Add

func Add[R Real, T Real](x, y T) R

Sub returns the sum of two real types, whilst casting to a (larger) type.

func IsInteger

func IsInteger[T Real](n T) bool

IsInteger returns true for instances that are signed or unsigned integers

func Max

func Max[T cmp.Ordered](xs ...T) T

Max returns the largest of one or more ordered values. Note the values can be strings as well as numeric types.

func Max2 added in v0.20.0

func Max2[T cmp.Ordered](x1, x2 T) T

func Min

func Min[T cmp.Ordered](xs ...T) T

Max returns the smallest of one or more ordered values. Note the values can be strings as well as numeric types.

func Min2 added in v0.20.0

func Min2[T cmp.Ordered](x1, x2 T) T

func Precision

func Precision[T Real](v T) int

Precision returns the number of bits of precision. For integers, this is simply the bit size of the integer (including the sign bit if present). For floating

func Sub

func Sub[R Real, T Real](x, y T) R

Sub returns the difference between two real types, whilst casting to a new type.

Types

type Real

type Real interface {
	constraints.Float | constraints.Integer
}

Scalar numeric type constraint. Includes all floating and integer types.

Jump to

Keyboard shortcuts

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