2 ms·
How is that zero cost? There's a blatantly obvious opportunity cost when you remove the associative and commutative properties.
by Conscat 4y ago
How is that zero cost? There's a blatantly obvious opportunity cost when you remove the associative and commutative properties.
- missblit 4y ago"Zero cost" here means the author is asserting it doesn't add a bunch of extra branches or instructions or whatever (compared to normal addition) by the time it gets compiled down to assembly. For example there's a slow looking if statement in there: if ((_is_neg() && _storage < usmin) || (!_is_neg() && _storage > usmax)) But in theory an optimizing compiler could remove it entirely since it can never be true (on C++20 or above). Whether the compiler does this in practice depends on a variety of factors, but in general they're fairly good at spotting "obvious" optimizations.