signbit
Returns whether x is negative or negative 0.
Function parameters
Parameters
- x:anytype
Returns whether x is negative or negative 0.
Functions
- signbit
- Returns whether x is negative or negative 0.
Source
Implementation
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;
}