From bed5c5b70f6bd42a1f917b5960f0f41aa8508345 Mon Sep 17 00:00:00 2001 From: dcode Date: Tue, 20 Oct 2020 16:42:05 +0200 Subject: [PATCH 1/2] Document masking of shift values --- src/types.md | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/types.md b/src/types.md index 0f4a8c113..3e0fa8ed7 100644 --- a/src/types.md +++ b/src/types.md @@ -84,6 +84,15 @@ The result of a bit shift \(`<<`, `>>`\) is the left type, with the right type i The result of an unsigned right shift \(`>>>`\) is the left type \(signedness is retained\), with the right type implicitly converted to the left type, but always performing a logical shift. +Note that only the `log2(sizeof())` least signficant bits of the shift affect the result: + +| Type | Significant bits | Example +| :-------- | :--------------: | :------------------------ +| i8 / u8 | 3 | `x & y` ≡ `x & (y & 7)` +| i16 / u16 | 4 | `x & y` ≡ `x & (y & 15)` +| i32 / u32 | 5 | `x & y` ≡ `x & (y & 31)` +| i64 / u64 | 6 | `x & y` ≡ `x & (y & 63)` + If the left type is a float, an error is emitted. ## Macro types From d9a43409dbea3facb0a5b8d1edded7a43cb1c43e Mon Sep 17 00:00:00 2001 From: dcode Date: Tue, 20 Oct 2020 16:43:21 +0200 Subject: [PATCH 2/2] fix indentation --- src/types.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/types.md b/src/types.md index 3e0fa8ed7..2dc8e1d57 100644 --- a/src/types.md +++ b/src/types.md @@ -91,7 +91,7 @@ Note that only the `log2(sizeof())` least signficant bits of the shift affect | i8 / u8 | 3 | `x & y` ≡ `x & (y & 7)` | i16 / u16 | 4 | `x & y` ≡ `x & (y & 15)` | i32 / u32 | 5 | `x & y` ≡ `x & (y & 31)` -| i64 / u64 | 6 | `x & y` ≡ `x & (y & 63)` +| i64 / u64 | 6 | `x & y` ≡ `x & (y & 63)` If the left type is a float, an error is emitted.