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
function mul(uint256 a, uint256 b) internal pure returns (uint256) {
if (a == 0) {
return 0;
}
uint256 c = a * b;
assert(c / a == b);
return c;
}
isn't written like this:
function mul(uint256 a, uint256 b) internal pure returns (uint256) {
if (a == 0 || b == 0) {
return 0;
}
uint256 c = a * b;
assert(c / a == b);
return c;
}
Why not check for b == 0 in the first if and return?
🐛 This is a bug report.
📈 This is a feature request.
? This is a question.
The text was updated successfully, but these errors were encountered:
Makes sense. Thanks! Is it really that rare to have b == 0? I'd be curious (but not too curious) to see a comparison of b == 0 with an explicit check and without.
@emn178here is assuming that most cases will be non-zero, which sounds reasonable. So this is about gas cost for this case, not about how rare is b = 0 compared to a = 0.
You can use remix as they did in the PR to satisfy your curiousity :)
🎉 Description
I'm just curious to know why this function:
isn't written like this:
Why not check for b == 0 in the first if and return?
The text was updated successfully, but these errors were encountered: