Zig 0.17.0-dev (Split by item)

This is an example of documentation generated by ZigDoc, an alternative to Zig's built-in Auto Doc feature. See also examples in other modes/formats. The project being documented here (as the example) is the Zig library itself.

signbit

Returns whether x is negative or negative 0.

signbit.signbit
pub fn signbit(x: anytype) bool

File

lib/std/math/signbit.zig:6

Code

pub fn signbit(x: anytype) bool {
    return switch (@typeInfo(@TypeOf(x))) {
        .int, .comptime_int => x,
        .float => |float| @as(@Int(.signed, float.bits), @bitCast(x)),
        .comptime_float => @as(i128, @bitCast(@as(f128, x))), // any float type will do
        else => @compileError("std.math.signbit does not support " ++ @typeName(@TypeOf(x))),
    } < 0;
}