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 AbsBounds[T Signed](a, b T) (min T, max T)
- func AbsMax[T Signed](a, b T) T
- func AbsMin[T Signed](a, b T) T
- func Bounds[T Numbers](a, b T) (min T, max T)
- func Diff[T Numbers](a, b T) T
- func FloatMillis[T Signed](in T) float64
- func Max[T Numbers](a, b T) T
- func Millis[T Signed](in float64) T
- func Min[T Numbers](a, b T) T
- func Range[T Numbers](a, b T) (start T, end 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 Atomic
- type AtomicFloat64
- func (a *AtomicFloat64) Add(delta float64) float64
- func (a *AtomicFloat64) CompareAndSwap(old, new float64) bool
- func (a *AtomicFloat64) Get() float64
- func (a *AtomicFloat64) Load() float64
- func (a *AtomicFloat64) Set(in float64)
- func (a *AtomicFloat64) Store(value float64)
- func (a *AtomicFloat64) Swap(new float64) float64
- type Numbers
- type Signed
- type Unsigned
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AbsBounds ¶ added in v0.10.4
func AbsBounds[T Signed](a, b T) (min T, max T)
AbsBounds resolves the absolute values of two numbers and then return the lower (absolute) value followed by the higher absolute value.
func AbsMax ¶
func AbsMax[T Signed](a, b T) T
AbsMax resolves the absolute value of both arguments and returns the larger value.
func AbsMin ¶
func AbsMin[T Signed](a, b T) T
AbsMin resolves the absolute value of both arguments and returns the smaller value.
func Bounds ¶ added in v0.10.4
func Bounds[T Numbers](a, b T) (min T, max T)
Bounds returns the two arguments as a (min,max): values less than zero become zero.
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 Range ¶ added in v0.10.4
func Range[T Numbers](a, b T) (start T, end T)
Range orders two numbers and returns the pair as (lower, higher).
func RoundToLargestMultiple ¶ added in v0.10.1
func RoundToLargestMultiple[T Signed](a, b T) T
RoundToLargestMultiple rounds up to a larger value: 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 Atomic ¶ added in v0.10.3
type Atomic[T Numbers] struct { // contains filtered or unexported fields }
Atomic is a wrapper around sync/atomic.Int64 that provides type-preserving atomic storage for all numeric types.
Atomic shares an interface with the adt.Atomic wrapper types.
func (*Atomic[T]) CompareAndSwap ¶ added in v0.10.3
type AtomicFloat64 ¶ added in v0.10.3
type AtomicFloat64 struct {
// contains filtered or unexported fields
}
AtomicFloat64 provides full-fidelity atomic storage for float64 values (by converting them) as bits to int64 and storing them using sync/atomic.Int64 values. The Add() method is correct, but must spin, unlike for integers which rely on an optimized underlying instruction.
AtomicFloat64 shares an interface with the adt.Atomic wrapper types.
func (*AtomicFloat64) Add ¶ added in v0.10.3
func (a *AtomicFloat64) Add(delta float64) float64
func (*AtomicFloat64) CompareAndSwap ¶ added in v0.10.3
func (a *AtomicFloat64) CompareAndSwap(old, new float64) bool
func (*AtomicFloat64) Get ¶ added in v0.10.3
func (a *AtomicFloat64) Get() float64
func (*AtomicFloat64) Load ¶ added in v0.10.3
func (a *AtomicFloat64) Load() float64
func (*AtomicFloat64) Set ¶ added in v0.10.3
func (a *AtomicFloat64) Set(in float64)
func (*AtomicFloat64) Store ¶ added in v0.10.3
func (a *AtomicFloat64) Store(value float64)
func (*AtomicFloat64) Swap ¶ added in v0.10.3
func (a *AtomicFloat64) Swap(new float64) float64