What does "-|" mean in zig?

I’m reading the GhostTTY devlogs and the author shows this bit of code:

const padding_x: f32 = (config.@"window-padding-x"* x_dpi) / 72;
const screen_width: u32 = self.width -| @as(u32, @intFromFloat(padding_x * 2));

What does -| mean here?

2 Likes

It’s called “Saturating Subtraction”. It means if you have a unsigned integer type that cannot go below zero, and you subtract a different integer that would cause the difference to be less than zero, it will just return zero instead. You can read more about it here: Documentation - The Zig Programming Language

13 Likes

Thank you very much, makes sense!

1 Like

I did not know zig had all of these kinds of operators, very cool.

2 Likes