aboutsummaryrefslogtreecommitdiff
path: root/lib/std/math.zig
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2022-10-12 05:26:11 -0400
committerGitHub <noreply@github.com>2022-10-12 05:26:11 -0400
commit7ce1ee1bce4d9ca05a647c9c390c6525be0b6362 (patch)
treea65ac3b2e1f252a1cc7c5efa6e70f0320034e823 /lib/std/math.zig
parentbec40a89c21009ea7f2c41362cc13d27f065b43e (diff)
parent8e2aaf6aed5213736f6cbbb374098e2394f19429 (diff)
downloadzig-7ce1ee1bce4d9ca05a647c9c390c6525be0b6362.tar.gz
zig-7ce1ee1bce4d9ca05a647c9c390c6525be0b6362.zip
Merge pull request #13081 from r00ster91/docs
fix(text): hyphenation and other fixes
Diffstat (limited to 'lib/std/math.zig')
-rw-r--r--lib/std/math.zig7
1 files changed, 4 insertions, 3 deletions
diff --git a/lib/std/math.zig b/lib/std/math.zig
index 2f16ecb5d8..4845808055 100644
--- a/lib/std/math.zig
+++ b/lib/std/math.zig
@@ -786,14 +786,14 @@ fn testOverflow() !void {
try testing.expect((shlExact(i32, 0b11, 4) catch unreachable) == 0b110000);
}
-/// Returns the absolute value of x, where x is a value of an integer
-/// type.
+/// Returns the absolute value of x, where x is a value of a signed integer type.
+/// See also: `absCast`
pub fn absInt(x: anytype) !@TypeOf(x) {
const T = @TypeOf(x);
comptime assert(@typeInfo(T) == .Int); // must pass an integer to absInt
comptime assert(@typeInfo(T).Int.signedness == .signed); // must pass a signed integer to absInt
- if (x == minInt(@TypeOf(x))) {
+ if (x == minInt(T)) {
return error.Overflow;
} else {
@setRuntimeSafety(false);
@@ -1001,6 +1001,7 @@ pub inline fn fabs(value: anytype) @TypeOf(value) {
/// Returns the absolute value of the integer parameter.
/// Result is an unsigned integer.
+/// See also: `absInt`
pub fn absCast(x: anytype) switch (@typeInfo(@TypeOf(x))) {
.ComptimeInt => comptime_int,
.Int => |int_info| std.meta.Int(.unsigned, int_info.bits),