Int

package
v0.0.0-...-d9f4d4e Latest Latest
Warning

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

Go to latest
Published: Feb 9, 2025 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package Int provides generic methods for working with integers.

Index

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

func Ceil[X Float.Any](x X) int

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

func Floor[X Float.Any](x X) int

Floor rounds x downward (towards negative infinity), returning the largest whole number that is not more than x.

func Max

func Max[T Any](a, b T) T

Max returns the largest of the two integers.

func Min

func Min[T Any](a, b T) T

Min returns the smallest of the two values.

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 Random

func Random() int

Random returns a random integer between min and max (inclusive).

func RandomBetween

func RandomBetween(min, max int) int

RandomBetween returns a random integer between min and max (inclusive).

func Round

func Round[X Float.Any](x X) int

Round rounds x to the nearest whole number, rounding halfway cases away from zero.

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.

func Snapped

func Snapped[X Any](val, by X) X

Snapped returns the multiple of step that is the closest to x. This can also be used to round a floating point number to an arbitrary number of decimals.

func Wrap

func Wrap[T ~int8 | ~int16 | ~int32 | ~int64 | ~int](value, min, max T) T

Wrap value between min and max. Can be used for creating loop-alike behavior or infinite surfaces.

Types

type Any

type Any interface {
	~int8 | ~int16 | ~int32 | ~int64 | ~int
}

Any integer.

Jump to

Keyboard shortcuts

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