menu
Arithmetic
import { Arithmetic } from "destack:math";
Explicit overflow behaviors for builtin integer arithmetic.
1export extension Arithmetic {2 checkedAdd(other: T): T | undefined;3 checkedSubtract(other: T): T | undefined;4 checkedMultiply(other: T): T | undefined;5 checkedDivide(other: T): T | undefined;6 checkedRemainder(other: T): T | undefined;7 checkedDivideEuclidean(other: T): T | undefined;8 checkedRemainderEuclidean(other: T): T | undefined;9 checkedNegate(): T | undefined;10 checkedAbs(): T | undefined;11 checkedPower(exponent: uint32): T | undefined;12 checkedShiftLeft(amount: uint32): T | undefined;13 checkedShiftRight(amount: uint32): T | undefined;14 overflowingAdd(other: T): (T, boolean);15 overflowingSubtract(other: T): (T, boolean);16 overflowingMultiply(other: T): (T, boolean);17 overflowingDivide(other: T): (T, boolean);18 overflowingRemainder(other: T): (T, boolean);19 overflowingDivideEuclidean(other: T): (T, boolean);20 overflowingRemainderEuclidean(other: T): (T, boolean);21 overflowingNegate(): (T, boolean);22 overflowingAbs(): (T, boolean);23 overflowingPower(exponent: uint32): (T, boolean);24 overflowingShiftLeft(amount: uint32): (T, boolean);25 overflowingShiftRight(amount: uint32): (T, boolean);26 wrappingAdd(other: T): T;27 wrappingSubtract(other: T): T;28 wrappingMultiply(other: T): T;29 wrappingDivide(other: T): T;30 wrappingRemainder(other: T): T;31 wrappingDivideEuclidean(other: T): T;32 wrappingRemainderEuclidean(other: T): T;33 wrappingNegate(): T;34 wrappingAbs(): T;35 wrappingPower(exponent: uint32): T;36 wrappingShiftLeft(amount: uint32): T;37 wrappingShiftRight(amount: uint32): T;38 saturatingAdd(other: T): T;39 saturatingSubtract(other: T): T;40 saturatingMultiply(other: T): T;41 saturatingNegate(): T;42 saturatingAbs(): T;43 saturatingPower(exponent: uint32): T;44 uncheckedAdd(other: T): T;45 uncheckedSubtract(other: T): T;46 uncheckedMultiply(other: T): T;47 uncheckedDivide(other: T): T;48 uncheckedRemainder(other: T): T;49 uncheckedShiftLeft(amount: uint32): T;50 uncheckedShiftRight(amount: uint32): T;51}Members
checkedAdd(other: T): T | undefinedReturn
this + other, orundefinedon overflow.checkedSubtract(other: T): T | undefinedReturn
this - other, orundefinedon overflow.checkedMultiply(other: T): T | undefinedReturn
this * other, orundefinedon overflow.checkedDivide(other: T): T | undefinedReturn
this / other, orundefinedon division by zero or overflow.checkedRemainder(other: T): T | undefinedReturn
this % other, orundefinedon division by zero or overflow.checkedDivideEuclidean(other: T): T | undefinedReturn the Euclidean quotient, or
undefinedon division by zero or overflow.checkedRemainderEuclidean(other: T): T | undefinedReturn the Euclidean remainder, or
undefinedon division by zero or overflow.checkedNegate(): T | undefinedReturn
-this, orundefinedon overflow.checkedAbs(): T | undefinedReturn the absolute value, or
undefinedon overflow.checkedPower(exponent: uint32): T | undefinedReturn
this ** exponent, orundefinedon overflow.checkedShiftLeft(amount: uint32): T | undefinedShift left, or
undefinedwhen the shift amount is out of range.checkedShiftRight(amount: uint32): T | undefinedShift right, or
undefinedwhen the shift amount is out of range.overflowingAdd(other: T): (T, boolean)Return wrapped
this + otherwith an overflow flag.overflowingSubtract(other: T): (T, boolean)Return wrapped
this - otherwith an overflow flag.overflowingMultiply(other: T): (T, boolean)Return wrapped
this * otherwith an overflow flag.overflowingDivide(other: T): (T, boolean)Return wrapped
this / otherwith an overflow flag.overflowingRemainder(other: T): (T, boolean)Return wrapped
this % otherwith an overflow flag.overflowingDivideEuclidean(other: T): (T, boolean)Return the wrapped Euclidean quotient with an overflow flag.
overflowingRemainderEuclidean(other: T): (T, boolean)Return the wrapped Euclidean remainder with an overflow flag.
overflowingNegate(): (T, boolean)Return wrapped
-thiswith an overflow flag.overflowingAbs(): (T, boolean)Return the wrapped absolute value with an overflow flag.
overflowingPower(exponent: uint32): (T, boolean)Return wrapped
this ** exponentwith an overflow flag.overflowingShiftLeft(amount: uint32): (T, boolean)Shift left with an out-of-range flag.
overflowingShiftRight(amount: uint32): (T, boolean)Shift right with an out-of-range flag.
wrappingAdd(other: T): TReturn
this + otherwith modular arithmetic.wrappingSubtract(other: T): TReturn
this - otherwith modular arithmetic.wrappingMultiply(other: T): TReturn
this * otherwith modular arithmetic.wrappingDivide(other: T): TReturn
this / other, wrapping the one overflowing case.wrappingRemainder(other: T): TReturn
this % other, wrapping the one overflowing case.wrappingDivideEuclidean(other: T): TReturn the Euclidean quotient, wrapping the one overflowing case.
wrappingRemainderEuclidean(other: T): TReturn the Euclidean remainder, wrapping the one overflowing case.
wrappingNegate(): TReturn
-thiswith modular arithmetic.wrappingAbs(): TReturn the absolute value with modular arithmetic.
wrappingPower(exponent: uint32): TReturn
this ** exponentwith modular arithmetic.wrappingShiftLeft(amount: uint32): TShift left with a masked shift amount.
wrappingShiftRight(amount: uint32): TShift right with a masked shift amount.
saturatingAdd(other: T): TReturn
this + other, clamping at the bounds.saturatingSubtract(other: T): TReturn
this - other, clamping at the bounds.saturatingMultiply(other: T): TReturn
this * other, clamping at the bounds.saturatingNegate(): TReturn
-this, clamping at the bounds.saturatingAbs(): TReturn the absolute value, clamping at the bounds.
saturatingPower(exponent: uint32): TReturn
this ** exponent, clamping at the bounds.uncheckedAdd(other: T): TAdd without overflow checks.
uncheckedSubtract(other: T): TSubtract without overflow checks.
uncheckedMultiply(other: T): TMultiply without overflow checks.
uncheckedDivide(other: T): TDivide without division checks.
uncheckedRemainder(other: T): TReturn a remainder without division checks.
uncheckedShiftLeft(amount: uint32): TShift left without checking the shift amount.
uncheckedShiftRight(amount: uint32): TShift right without checking the shift amount.