In VB.NET the following code causes an overflow.
Dim t As UInt64
t = UInt64.MaxValue
t += 2UL
It is my understanding that in C it “wraps”. Assuming that is true, is there a way to mimic this in Visual Basic? I need this for an implementation of UInt128 I am trying to write.
I don’t know VB specifically (so you’ll have to convert it yourself) but the usual way of doing this is:
It basically figures out in advance whether there will be overflow and turns an
add(N)operation into ansub(maxvalue-N+1)one.Both the test and the add/sub are safe within the range
0..maxvalue.