zig/std/math/signbit.zig
Andrew Kelley 3671582c15 syntax: functions require return type. remove ->
The purpose of this is:

 * Only one way to do things
 * Changing a function with void return type to return a possible
   error becomes a 1 character change, subtly encouraging
   people to use errors.

See #632

Here are some imperfect sed commands for performing this update:

remove arrow:

```
sed -i 's/\(\bfn\b.*\)-> /\1/g' $(find . -name "*.zig")
```

add void:

```
sed -i 's/\(\bfn\b.*\))\s*{/\1) void {/g' $(find ../ -name "*.zig")
```

Some cleanup may be necessary, but this should do the bulk of the work.
2018-01-25 04:10:11 -05:00

38 lines
801 B
Zig

const std = @import("../index.zig");
const math = std.math;
const assert = std.debug.assert;
pub fn signbit(x: var) bool {
const T = @typeOf(x);
return switch (T) {
f32 => signbit32(x),
f64 => signbit64(x),
else => @compileError("signbit not implemented for " ++ @typeName(T)),
};
}
fn signbit32(x: f32) bool {
const bits = @bitCast(u32, x);
return bits >> 31 != 0;
}
fn signbit64(x: f64) bool {
const bits = @bitCast(u64, x);
return bits >> 63 != 0;
}
test "math.signbit" {
assert(signbit(f32(4.0)) == signbit32(4.0));
assert(signbit(f64(4.0)) == signbit64(4.0));
}
test "math.signbit32" {
assert(!signbit32(4.0));
assert(signbit32(-3.0));
}
test "math.signbit64" {
assert(!signbit64(4.0));
assert(signbit64(-3.0));
}