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 ¶
- func Abs[T Signed](in T) T
- func AbsMax[T Signed](a, b T) T
- func AbsMin[T Signed](a, b T) T
- func Diff[T Numbers](a, b T) T
- func FloatMillis(in int64) float64
- func Max[T Numbers](a, b T) T
- func Millis(in float64) int64
- func Min[T Numbers](a, b T) T
- func RoundToLargestMultiple[T Signed](a, b T) T
- func RoundToMultipleAwayFromZero[T Signed](a, b T) T
- func RoundToMultipleTowardZero[T Signed](a, b T) T
- func RoundToSmallestMultiple[T Signed](a, b T) T
- type Numbers
- type Signed
- type Unsigned
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
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
FloatMillis reverses, though potentially (often) not without some loss of fidelity
func Millis ¶
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 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.