Saturating(T)
Inherits Comparable / Comparable / Struct / Value / Object
A Saturating Number clamps to its maximum or minimum values instead of
overflowing.
This wrapper type changes overflow behavior to saturate at the contained
Number type's minimum and maximum. The code snippet below demonstrates
this concept with an Int32.
n = Saturating(Int32).new(Int32::MAX)
n += 1 # => 2147483647 (Int32::MAX)
n = Saturating(Int32).new(Int32::MIN)
n -= 1 # => -2147483648 (Int32::MIN)
Note: This class will only work with Number types. In order to avoid
unexpected behavior, T is checked at compile-time to determine
whether it is a Number type.
Constructors
Instance methods
Returns the result of multiplying self and other.
Returns T::MAX or T::MIN (as appropriate) in case of overflow.
Returns the result of multiplying self and other.
Returns T::MAX or T::MIN (as appropriate) in case of overflow.
Returns the result of adding self and other.
Returns T::MAX or T::MIN (as appropriate) in case of overflow.
Returns the result of adding self and other.
Returns T::MAX or T::MIN (as appropriate) in case of overflow.
Returns the result of subtracting other from self.
Returns T::MAX or T::MIN (as appropriate) in case of overflow.
Returns the result of subtracting other from self.
Returns T::MAX or T::MIN (as appropriate) in case of overflow.