mirror of
https://github.com/ziglang/zig.git
synced 2024-11-27 07:32:44 +00:00
@shlExact
fixups
* Add clarification in langref * move test case to behavior tests
This commit is contained in:
parent
10016e0368
commit
52ebba6bdf
@ -9163,6 +9163,11 @@ test "@setRuntimeSafety" {
|
|||||||
The type of {#syntax#}shift_amt{#endsyntax#} is an unsigned integer with {#syntax#}log2(@typeInfo(T).Int.bits){#endsyntax#} bits.
|
The type of {#syntax#}shift_amt{#endsyntax#} is an unsigned integer with {#syntax#}log2(@typeInfo(T).Int.bits){#endsyntax#} bits.
|
||||||
This is because {#syntax#}shift_amt >= @typeInfo(T).Int.bits{#endsyntax#} is undefined behavior.
|
This is because {#syntax#}shift_amt >= @typeInfo(T).Int.bits{#endsyntax#} is undefined behavior.
|
||||||
</p>
|
</p>
|
||||||
|
<p>
|
||||||
|
{#syntax#}comptime_int{#endsyntax#} is modeled as an integer with an infinite number of bits,
|
||||||
|
meaning that in such case, {#syntax#}@shlExact{#endsyntax#} always produces a result and
|
||||||
|
cannot produce a compile error.
|
||||||
|
</p>
|
||||||
{#see_also|@shrExact|@shlWithOverflow#}
|
{#see_also|@shrExact|@shlWithOverflow#}
|
||||||
{#header_close#}
|
{#header_close#}
|
||||||
|
|
||||||
|
@ -1314,6 +1314,8 @@ test "exact shift left" {
|
|||||||
|
|
||||||
try testShlExact(0b00110101);
|
try testShlExact(0b00110101);
|
||||||
try comptime testShlExact(0b00110101);
|
try comptime testShlExact(0b00110101);
|
||||||
|
|
||||||
|
if (@shlExact(1, 1) != 2) @compileError("should be 2");
|
||||||
}
|
}
|
||||||
fn testShlExact(x: u8) !void {
|
fn testShlExact(x: u8) !void {
|
||||||
const shifted = @shlExact(x, 2);
|
const shifted = @shlExact(x, 2);
|
||||||
|
@ -1,6 +0,0 @@
|
|||||||
export fn entry() void {
|
|
||||||
if (@shlExact(1, 1) != 2) @compileError("should be 2");
|
|
||||||
}
|
|
||||||
|
|
||||||
// compile
|
|
||||||
// output_mode=Obj
|
|
Loading…
Reference in New Issue
Block a user