Function signbit [src]

Alias for std.math.signbit.signbit

Returns whether x is negative or negative 0.

Prototype

pub fn signbit(x: anytype) bool

Example

test signbit { try testInts(i0); try testInts(u0); try testInts(i1); try testInts(u1); try testInts(i2); try testInts(u2); try testFloats(f16); try testFloats(f32); try testFloats(f64); try testFloats(f80); try testFloats(f128); try testFloats(c_longdouble); try testFloats(comptime_float); }

Source

pub fn signbit(x: anytype) bool { return switch (@typeInfo(@TypeOf(x))) { .int, .comptime_int => x, .float => |float| @as(@Type(.{ .int = .{ .signedness = .signed, .bits = 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; }