ints

package
v1.1.17 Latest Latest
Warning

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

Go to latest
Published: Oct 5, 2023 License: BSD-3-Clause Imports: 1 Imported by: 79

Documentation

Overview

Package ints provides a standard Inter interface and basic functions defined on Inter types that support core things like Max, Min, Abs. Furthermore, fully generic slice sort and conversion methods in the kit type kit package attempt to use this interface, before falling back on reflection. If you have a struct that can be converted into an int64, then this is the only way to allow it to be sorted using those generic functions, as the reflect.Kind fallback will fail.

It also includes Max, Min, Abs for builtin int64, int32 types.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Abs

func Abs(a Inter) int64

Abs computes the absolute value of the given value

func Abs32

func Abs32(a int32) int32

Abs32 computes the absolute value of the given value

func Abs64

func Abs64(a int64) int64

Abs64 computes the absolute value of the given value

func AbsInt

func AbsInt(a int) int

AbsInt computes the absolute value of the given value

func ClipInt added in v1.1.6

func ClipInt(a, min, max int) int

ClipInt clips int within min, max range (max exclusive, min inclusive)

func IntMultiple added in v1.1.10

func IntMultiple(val, mod int) int

IntMultiple returns the interger multiple of mod that is always >= given value: int(Ceil(val / mod)) * mod

func Max32

func Max32(a, b int32) int32

Max32 computes the maximum of the two int32 args

func Max64

func Max64(a, b int64) int64

Max64 computes the maximum of the two int64 args

func MaxInt

func MaxInt(a, b int) int

MaxInt computes the maximum of the two int args

func Min32

func Min32(a, b int32) int32

Min32 computes the minimum of the two int32 args

func Min64

func Min64(a, b int64) int64

Min64 computes the minimum of the two int64 args

func MinInt

func MinInt(a, b int) int

MinInt computes the minimum of the two int args

Types

type IntSetter

type IntSetter interface {
	Inter
	FromInt(val int64)
}

IntSetter is an Inter that can also be set from an int. Satisfying this interface requires a pointer to the underlying type.

type Inter

type Inter interface {
	Int() int64
}

Inter converts a type from an int64, used in kit.ToInt and in sorting comparisons. See also Floater in floats package.

func Max

func Max(a, b Inter) Inter

Max computes the maximum of the two Inter args

func Min

func Min(a, b Inter) Inter

Min computes the minimum of the two Inter args

Jump to

Keyboard shortcuts

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