Documentation
¶
Overview ¶
Package Int provides generic methods for working with integers.
Index ¶
- func Abs[X Any](v X) X
- func Ceil[X Float.Any](x X) int
- func Clamp[X Any](value, min, max X) X
- func Floor[X Float.Any](x X) int
- func Max[T Any](a, b T) T
- func Min[T Any](a, b T) T
- func NearestPowerOfTwo[T Any](x T) T
- func Posmod[T Any](x, y T) T
- func Random() int
- func RandomBetween(min, max int) int
- func Round[X Float.Any](x X) int
- func Sign[X Any](x X) X
- func Snapped[X Any](val, by X) X
- func Wrap[T ~int8 | ~int16 | ~int32 | ~int64 | ~int](value, min, max T) T
- type Any
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Abs ¶
func Abs[X Any](v X) X
Absi returns the absolute value of the integer parameter x (i.e. non-negative value).
func Ceil ¶
Ceil rounds x upward (towards positive infinity), returning the smallest whole number that is not less than x.
func Clamp ¶
func Clamp[X Any](value, min, max X) X
Clamp clamps the value, returning an integer not less than min and not more than max.
func Floor ¶
Floor rounds x downward (towards negative infinity), returning the largest whole number that is not more than x.
func NearestPowerOfTwo ¶
func NearestPowerOfTwo[T Any](x T) T
NearestPowerOfTwo returns the smallest integer power of 2 that is greater than or equal to value.
func Posmod ¶
func Posmod[T Any](x, y T) T
Posmod returns the integer modulus of x divided by y that wraps equally in positive and negative.
func RandomBetween ¶
RandomBetween returns a random integer between min and max (inclusive).
func Sign ¶
func Sign[X Any](x X) X
Sign returns -1 if x is negative, 1 if x is positive, and 0 if x is zero. For NaN values of x it returns 0.