| | @@ -52,6 +52,7 @@ |
| 52 | 52 | rotated (sections 6.1 and 6.8); it breaks no program. 2026-10.36 is a |
| 53 | 53 | twelfth: `MIN(T)` and `MAX(T)`, the limits of an integer type, and |
| 54 | 54 | `CLZ`, `CTZ` and `POPCOUNT`, which count bits (sections 6.1 and 6.8); |
| 55 | +`ABS(x)`, a number without its sign (sections 6.1 and 6.8); |
| 55 | 56 | `INT(b)`, a `BOOL` as an integer (section 6.7); `OFFSET(T, f)` and |
| 56 | 57 | `SIZE(T.f)`, where a field lies and how big it is; `BYTES(x)`, the |
| 57 | 58 | bytes of a variable or a slice (sections 4 and 6.8); `FILL(d, x)`, an |
| | @@ -390,8 +391,8 @@ |
| 390 | 391 | |
| 391 | 392 | **Constants** are evaluated by the compiler. Their expressions use only |
| 392 | 393 | literals, other constants, operators, conversions, `SIZE`, `OFFSET`, the `LEN` |
| 393 | | -of arrays and strings, `MIN`, `MAX`, `ROL`, `ROR`, `CLZ`, `CTZ`, |
| 394 | | -`POPCOUNT`, and a variant's cases. A constant is an integer, |
| 394 | +of arrays and strings, `MIN`, `MAX`, `ABS`, `ROL`, `ROR`, `CLZ`, |
| 395 | +`CTZ`, `POPCOUNT`, and a variant's cases. A constant is an integer, |
| 395 | 396 | a real, a `BOOL`, a name of an enumeration, a set, a string, an array, |
| 396 | 397 | a record, a variant or an `ERROR`. A constant of an integer type wraps as the |
| 397 | 398 | program would: `U8(250) + 10` is 4. Dividing by zero in a constant is |
| | @@ -862,6 +863,14 @@ |
| 862 | 863 | own type, as a hexadecimal number above it has (section 2). Each of the five, given constants, is a |
| 863 | 864 | constant (section 4). |
| 864 | 865 | |
| 866 | +`ABS(x)` (section 6.8) is `x` without its sign, of `x`'s type, for an |
| 867 | +integer or a real. For a signed integer it is `-x` if `x < 0`, so the |
| 868 | +smallest value of the type gives itself, as `-x` does; for an unsigned |
| 869 | +type it is `x`. For a real it clears the sign bit: `ABS(-0.0)` is 0.0, |
| 870 | +`ABS` of a NaN is a NaN, and of minus infinity is infinity. Of a |
| 871 | +constant it is a constant; of an untyped one, the untyped absolute |
| 872 | +value, `ABS(-5)` is 5, which doesn't wrap. |
| 873 | + |
| 865 | 874 | Relations compare as signed or unsigned according to the type. |
| 866 | 875 | |
| 867 | 876 | ### 6.2 Booleans |
| | @@ -1008,6 +1017,7 @@ |
| 1008 | 1017 | | `CAS(p, old, new)` | if `p^ = old`, sets `p^ := new` and returns `true`; atomically | |
| 1009 | 1018 | | `XCHG(p, x)` | sets `p^ := x` and returns the value before, atomically | |
| 1010 | 1019 | | `XADD(p, x)` | adds `x` to `p^` and returns the value before, atomically | |
| 1020 | +| `ABS(x)` | `x` without its sign, of `x`'s type; for an integer, `-x` if `x < 0`, so the smallest `I64` gives itself, as `-x` does; for a real, the sign cleared; `x` of a numeric type (section 6.1) | |
| 1011 | 1021 | | `ROL(x, n)`, `ROR(x, n)` | `x` rotated left, or right, by `n` bits modulo its width; `x` of an unsigned integer type (section 6.1) | |
| 1012 | 1022 | | `CLZ(x)`, `CTZ(x)` | the number of zero bits above the highest one in `x`, or below the lowest one, an `INT`; the width of `x`'s type if `x` is 0; `x` of an unsigned integer type | |
| 1013 | 1023 | | `POPCOUNT(x)` | the number of one bits in `x`, or of members of the set `x`, an `INT`; `x` of an unsigned integer type or a set | |