raz / commit c62232a1

commit
c62232a1b8913952ab8237f0e67b2a11c22b9497
author
Luis <42945842+ldiaz94@users.noreply.github.com>
date
parent
20bd6310
raz.md: ABS(x), a number without its sign

patch · log

3 files changed, +17 -2

doc/raz.7 (history) modified +3 -0

@@ -495,6 +495,9 @@
495495 Set, or add to,
496496 .Ar p Ns ^ ,
497497 returning the value before; atomically.
498+.It Fn ABS x
499+.Ar x
500+without its sign, of its type: an integer or a real.
498501 .It Fn ROL x n , Fn ROR x n
499502 .Ar x ,
500503 of an unsigned integer type, rotated left or right by

doc/raz.md (history) modified +12 -2

@@ -52,6 +52,7 @@
5252 rotated (sections 6.1 and 6.8); it breaks no program. 2026-10.36 is a
5353 twelfth: `MIN(T)` and `MAX(T)`, the limits of an integer type, and
5454 `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);
5556 `INT(b)`, a `BOOL` as an integer (section 6.7); `OFFSET(T, f)` and
5657 `SIZE(T.f)`, where a field lies and how big it is; `BYTES(x)`, the
5758 bytes of a variable or a slice (sections 4 and 6.8); `FILL(d, x)`, an
@@ -390,8 +391,8 @@
390391
391392 **Constants** are evaluated by the compiler. Their expressions use only
392393 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,
395396 a real, a `BOOL`, a name of an enumeration, a set, a string, an array,
396397 a record, a variant or an `ERROR`. A constant of an integer type wraps as the
397398 program would: `U8(250) + 10` is 4. Dividing by zero in a constant is
@@ -862,6 +863,14 @@
862863 own type, as a hexadecimal number above it has (section 2). Each of the five, given constants, is a
863864 constant (section 4).
864865
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+
865874 Relations compare as signed or unsigned according to the type.
866875
867876 ### 6.2 Booleans
@@ -1008,6 +1017,7 @@
10081017 | `CAS(p, old, new)` | if `p^ = old`, sets `p^ := new` and returns `true`; atomically |
10091018 | `XCHG(p, x)` | sets `p^ := x` and returns the value before, atomically |
10101019 | `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) |
10111021 | `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) |
10121022 | `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 |
10131023 | `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 |

doc/report-history.md (history) modified +2 -0

@@ -236,6 +236,8 @@
236236 not core. And a twelfth thaw, by the owner's word: `MIN(T)` and
237237 `MAX(T)`, the smallest and largest value of an integer type, untyped
238238 constants but for `MAX(U64)` and `MAX(UINT)`, which keep their type;
239+ `ABS(x)`, a number without its sign, of `x`'s type, an integer or a
240+ real, and of a constant a constant (sections 4, 6.1 and 6.8);
239241 and `CLZ(x)`, `CTZ(x)` and `POPCOUNT(x)`, which count the
240242 zero bits above the highest one, below the lowest one, and the one
241243 bits (or members of a set) of a word of an unsigned integer type, an