Is there a way using Swifts UInt32(CUnsignedInt) to handle arithmetic overflows?
Asked
Active
Viewed 118 times
1 Answers
1
You can use these method here, I believe it's also the same methods across all Int
of different sizes
UInt32.addWithOverflow(x,y)
UInt32.multiplyWithOverflow(x, y)
UInt32.divideWithOverflow(x, y)
UInt32.subtractWithOverflow(x, y)
each of them returns a tuple of size 2 with the result and whether it overflowed or not.
Referenced from How does one trap arithmetic overflow errors in Swift?

TNguyen
- 1,041
- 9
- 24