diff --git a/doc/langref.html.in b/doc/langref.html.in
index a5dfa5c927..b6f49dab62 100644
--- a/doc/langref.html.in
+++ b/doc/langref.html.in
@@ -1244,8 +1244,9 @@ fn divide(a: i32, b: i32) i32 {
Operators such as {#syntax#}+{#endsyntax#} and {#syntax#}-{#endsyntax#} cause undefined behavior on
- integer overflow. Also available are operations such as {#syntax#}+%{#endsyntax#} and
- {#syntax#}-%{#endsyntax#} which are defined to have wrapping arithmetic on all targets.
+ integer overflow. Alternative operators are provided for wrapping and saturating arithmetic on all targets.
+ {#syntax#}+%{#endsyntax#} and {#syntax#}-%{#endsyntax#} perform wrapping arithmetic
+ while {#syntax#}+|{#endsyntax#} and {#syntax#}-|{#endsyntax#} perform saturating arithmetic.
Zig supports arbitrary bit-width integers, referenced by using
@@ -1395,6 +1396,24 @@ a +%= b{#endsyntax#}
{#syntax#}@as(u32, std.math.maxInt(u32)) +% 1 == 0{#endsyntax#}
+
+ {#syntax#}a +| b
+a +|= b{#endsyntax#} |
+
+
+ |
+ Saturating Addition.
+
+ - Invokes {#link|Peer Type Resolution#} for the operands.
+ - See also {#link|@addWithSaturation#}.
+
+ |
+
+ {#syntax#}@as(u32, std.math.maxInt(u32)) +| 1 == @as(u32, std.math.maxInt(u32)){#endsyntax#}
+ |
+
{#syntax#}a - b
a -= b{#endsyntax#} |
@@ -1434,6 +1453,24 @@ a -%= b{#endsyntax#}
{#syntax#}@as(u32, 0) -% 1 == std.math.maxInt(u32){#endsyntax#}
+
+ {#syntax#}a -| b
+a -|= b{#endsyntax#} |
+
+
+ |
+ Saturating Subtraction.
+
+ - Invokes {#link|Peer Type Resolution#} for the operands.
+ - See also {#link|@subWithSaturation#}.
+
+ |
+
+ {#syntax#}@as(u32, 0) -| 1 == 0{#endsyntax#}
+ |
+
{#syntax#}-a{#endsyntax#} |
@@ -1508,6 +1545,24 @@ a *%= b{#endsyntax#}
{#syntax#}@as(u8, 200) *% 2 == 144{#endsyntax#}
|
+
+ {#syntax#}a *| b
+a *|= b{#endsyntax#} |
+
+
+ |
+ Saturating Multiplication.
+
+ - Invokes {#link|Peer Type Resolution#} for the operands.
+ - See also {#link|@mulWithSaturation#}.
+
+ |
+
+ {#syntax#}@as(u8, 200) *| 2 == 255{#endsyntax#}
+ |
+
{#syntax#}a / b
a /= b{#endsyntax#} |
@@ -1577,6 +1632,24 @@ a <<= b{#endsyntax#}
{#syntax#}1 << 8 == 256{#endsyntax#}
+
+ {#syntax#}a <<| b
+a <<|= b{#endsyntax#} |
+
+
+ |
+ Saturating Bit Shift Left.
+
+ - See also {#link|@shlExact#}.
+ - See also {#link|@shlWithOverflow#}.
+
+ |
+
+ {#syntax#}@as(u8, 1) <<| 8 == 255{#endsyntax#}
+ |
+
{#syntax#}a >> b
a >>= b{#endsyntax#} |
@@ -1968,14 +2041,14 @@ const B = error{Two};
a!b
x{}
!x -x -%x ~x &x ?x
-* / % ** *% ||
-+ - ++ +% -%
-<< >>
+* / % ** *% *| ||
++ - ++ +% -% +| -|
+<< >> <<|
& ^ | orelse catch
== != < > <= >=
and
or
-= *= /= %= += -= <<= >>= &= ^= |={#endsyntax#}
+= *= *%= *|= /= %= += +%= +|= -= -%= -|= <<= <<|= >>= &= ^= |={#endsyntax#}
{#header_close#}
{#header_close#}
{#header_open|Arrays#}
@@ -11839,6 +11912,7 @@ AssignOp
/ PLUSEQUAL
/ MINUSEQUAL
/ LARROW2EQUAL
+ / LARROW2PIPEEQUAL
/ RARROW2EQUAL
/ AMPERSANDEQUAL
/ CARETEQUAL
@@ -11873,6 +11947,8 @@ AdditionOp
/ PLUS2
/ PLUSPERCENT
/ MINUSPERCENT
+ / PLUSPIPE
+ / MINUSPIPE
MultiplyOp
<- PIPE2
@@ -11881,6 +11957,7 @@ MultiplyOp
/ PERCENT
/ ASTERISK2
/ ASTERISKPERCENT
+ / ASTERISKPIPE
PrefixOp
<- EXCLAMATIONMARK
@@ -12044,6 +12121,8 @@ ASTERISK2 <- '**' skip
ASTERISKEQUAL <- '*=' skip
ASTERISKPERCENT <- '*%' ![=] skip
ASTERISKPERCENTEQUAL <- '*%=' skip
+ASTERISKPIPE <- '*|' ![=] skip
+ASTERISKPIPEEQUAL <- '*|=' skip
CARET <- '^' ![=] skip
CARETEQUAL <- '^=' skip
COLON <- ':' skip
@@ -12060,6 +12139,8 @@ EXCLAMATIONMARK <- '!' ![=] skip
EXCLAMATIONMARKEQUAL <- '!=' skip
LARROW <- '<' ![<=] skip
LARROW2 <- '<<' ![=] skip
+LARROW2PIPE <- '<<|' ![=] skip
+LARROW2PIPEEQUAL <- '<<|=' ![=] skip
LARROW2EQUAL <- '<<=' skip
LARROWEQUAL <- '<=' skip
LBRACE <- '{' skip
@@ -12069,6 +12150,8 @@ MINUS <- '-' ![%=>] skip
MINUSEQUAL <- '-=' skip
MINUSPERCENT <- '-%' ![=] skip
MINUSPERCENTEQUAL <- '-%=' skip
+MINUSPIPE <- '-|' ![=] skip
+MINUSPIPEEQUAL <- '-|=' skip
MINUSRARROW <- '->' skip
PERCENT <- '%' ![=] skip
PERCENTEQUAL <- '%=' skip
@@ -12080,6 +12163,8 @@ PLUS2 <- '++' skip
PLUSEQUAL <- '+=' skip
PLUSPERCENT <- '+%' ![=] skip
PLUSPERCENTEQUAL <- '+%=' skip
+PLUSPIPE <- '+|' ![=] skip
+PLUSPIPEEQUAL <- '+|=' skip
LETTERC <- 'c' skip
QUESTIONMARK <- '?' skip
RARROW <- '>' ![>=] skip