Overflow arithmetic vs saturating arithmetic vs regular arithmetic
Working on optimizing search for a byte in a buffer for [stdlib] Add to Unsafe[Mutable]RawBufferPointer implementation of _custom[Last]IndexOfEquatableElement
return to blog post Finding Bytes in Arrays. Now I bookmark it here to save search time when I will need it next time.
Working on above mentioned PR I came across &+
and alike operations. I wrongly call these operations saturating operations (saturating arithmetic). Wiki: Saturation arithmetic. Saturation arithmetic clamps result to minimum and maximum values.
Typically, general-purpose microprocessors do not implement integer arithmetic operations using saturation arithmetic; instead, they use the easier-to-implement modular arithmetic, in which values exceeding the maximum value “wrap around” to the minimum value, like the hours on a clock passing from 12 to 1.
This is exactly what Swift implements - Overflow Operators.