intish

package
v0.10.2 Latest Latest
Warning

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

Go to latest
Published: Jul 26, 2023 License: Apache-2.0 Imports: 1 Imported by: 3

Documentation

Overview

Package intish provides a collection of strongly type integer arithmetic operations, to make it possible to avoid floating point math for simple operations when desired.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Abs

func Abs[T Signed](in T) T

Abs returns the absolute value of the integer.

func AbsMax

func AbsMax[T Signed](a, b T) T

func AbsMin

func AbsMin[T Signed](a, b T) T

func Diff

func Diff[T Numbers](a, b T) T

Diff returns the absolute value of the difference between two values.

func FloatMillis added in v0.10.1

func FloatMillis(in int64) float64

FloatMillis reverses, though potentially (often) not without some loss of fidelity

func Max

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

Max returns the highest value.

func Millis

func Millis(in float64) int64

Millis converts a float into a an integer that represents one thousandth of the units of the original.

Millis will panic in the case of an overflow (wraparound).

func Min

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

Min returns the lowest value.

func RoundToLargestMultiple added in v0.10.1

func RoundToLargestMultiple[T Signed](a, b T) T

The argument with the smaller absolute value is always the "multiple" and the "larger" is always the value that is rounded.

The output value is always *larget* than the input value.

func RoundToMultipleAwayFromZero

func RoundToMultipleAwayFromZero[T Signed](a, b T) T

RoundToMultipleAwayFromZero rounds a value to the nearest multiple of the other number. The argument with the smaller absolute value is always the "multiple" and value with larger absolute value is rounded.

The rounded always has a higher absolute value than the input value.

func RoundToMultipleTowardZero

func RoundToMultipleTowardZero[T Signed](a, b T) T

RoundToMultipleTowardZero rounds a value to the nearest multiple of the other number. The argument with the smaller absolute value is always the "multiple" and value with larger absolute value is rounded.

The rounded always has a lower absolute value than the input value.

func RoundToSmallestMultiple added in v0.10.1

func RoundToSmallestMultiple[T Signed](a, b T) T

RoundToSmallestMultiple rounds to smaller numbers, The argument with the smaller absolute value is always the "multiple" and the "larger" is always the value that is rounded.

The rounded value is always *smaller* than the input value.

Types

type Numbers

type Numbers interface {
	Signed | Unsigned
}

Numbers are the set of singed and unsinged integers, used by this package.

type Signed

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

Signed are all of the primitive signed integer types in go.

type Unsigned

type Unsigned interface {
	~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64 | ~uintptr
}

Unsigned are all of the primitive signed integer types in go.

Jump to

Keyboard shortcuts

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