You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When a user does a+b where a and b are u32s. If a+b exceeds the value of a 32 bit integer, the default behaviour is to wrap around and not fail.
There are usecases for not checking integer overflow, and there are usecases for checking integer overflow. This issue is concerned with what the deault behaviour should be.
Solution
Enable overflow checks by default, and if users want to add with overflow, they call a method such as overflow_add
(Describe your suggestion.)
Alternatives considered
Not enable overflow checks and if users want to check for overflow, they call a method named checked_add
Additional context
(If applicable.)
The text was updated successfully, but these errors were encountered:
The main argument against this addition is concerns for performance. Although one should note that the compiler is smart enough to evade some overflow checks due to field sizes.
For example:
fnadd3(a:u32,b:u32,c:u32) -> u32{
a + b + c
}
In the above code, if overflow checks are enabled then the compiler could add a with b with c as a Field, then check if that result is larger than a u32. Instead of checking if a+b = d overflows then checking if d+c
The problem is that you need to do the check before and after each subtraction, else you would not detect this case (using u8, simpler to write): 255+5-10.
And then this would not work at all with signed integers (i.e we need to check for every operation)
Problem
When a user does
a+b
wherea
andb
are u32s. Ifa+b
exceeds the value of a 32 bit integer, the default behaviour is to wrap around and not fail.There are usecases for not checking integer overflow, and there are usecases for checking integer overflow. This issue is concerned with what the deault behaviour should be.
Solution
Enable overflow checks by default, and if users want to add with overflow, they call a method such as
overflow_add
(Describe your suggestion.)
Alternatives considered
Not enable overflow checks and if users want to check for overflow, they call a method named
checked_add
Additional context
(If applicable.)
The text was updated successfully, but these errors were encountered: