|
|
|
|
|
by AlienRobot
49 days ago
|
|
Zig raises overflow. There are +|= and +%= operators for clamped and wrapping addition. Rust doesn't raise overflow by default. But you can just 123.checked_add(321). Now your code is unreadable, but it's overflow safe. Honestly, based on the way I write code I'd rather something like an end of line comment. Like: var x = y + z; # wrapped
Because I'm very unlikely to mix wrapped/checked/clamped arithmetic in a single line. It can't be a compiler state like doing(wrapped) { x + y } because in Zig every line must be "compilable" by itself, without requiring context from other parts of the code. Function names are too verbose. Casting is too verbose. Having a statement-level modifier would be a good compromise. |
|