Thank you very much, I thought the operators are alrdy checked by
if (op == "+" || op == "-" || op == "/")

But I did same tests for ushort uint and ulong, but for ulong it didn't compile.

unittest{
        alias sulong = Saturated!ulong;
assert(sulong(18_446_744_073_709_551_610) + sulong(2) == sulong(18_446_744_073_709_551_612)); assert(sulong(18_446_744_073_709_551_614) + sulong(2) == sulong(18_446_744_073_709_551_615));

It failed to compile

Error: signed integer overflow

So I appended uL to each number and it worked.

assert(sulong(18_446_744_073_709_551_610uL) + sulong(2uL) == sulong(18_446_744_073_709_551_612uL));

Was it the right idea to fix it? And if so, do I always have to use a suffix when the number is bigger than uint?

Reply via email to