mirror of
https://github.com/ziglang/zig.git
synced 2025-12-10 08:13:07 +00:00
* unify the logic for exporting math functions from compiler-rt,
with the appropriate suffixes and prefixes.
- add all missing f128 and f80 exports. Functions with missing
implementations call other functions and have TODO comments.
- also add f16 functions
* move math functions from freestanding libc to compiler-rt (#7265)
* enable all the f128 and f80 code in the stage2 compiler and behavior
tests (#11161).
* update std lib to use builtins rather than `std.math`.
30 lines
671 B
Zig
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);
|
|
}
|