zig/lib/compiler_rt/fabs.zig
Andrew Kelley ec95e00e28 flatten lib/std/special and improve "pkg inside another" logic
stage2: change logic for detecting whether the main package is inside
the std package. Previously it relied on realpath() which is not portable.
This uses resolve() which is how imports already work.

 * stage2: fix cleanup bug when creating Module
 * flatten lib/std/special/* to lib/*
   - this was motivated by making main_pkg_is_inside_std false for
     compiler_rt & friends.
 * rename "mini libc" to "universal libc"
2022-05-06 22:41:00 -07:00

30 lines
671 B
Zig

const std = @import("std");
pub fn __fabsh(a: f16) callconv(.C) f16 {
return generic_fabs(a);
}
pub fn fabsf(a: f32) callconv(.C) f32 {
return generic_fabs(a);
}
pub fn fabs(a: f64) callconv(.C) f64 {
return generic_fabs(a);
}
pub fn __fabsx(a: f80) callconv(.C) f80 {
return generic_fabs(a);
}
pub fn fabsq(a: f128) callconv(.C) f128 {
return generic_fabs(a);
}
inline fn generic_fabs(x: anytype) @TypeOf(x) {
const T = @TypeOf(x);
const TBits = std.meta.Int(.unsigned, @typeInfo(T).Float.bits);
const float_bits = @bitCast(TBits, x);
const remove_sign = ~@as(TBits, 0) >> 1;
return @bitCast(T, float_bits & remove_sign);
}