mirror of
https://codeberg.org/ziglang/zig.git
synced 2026-04-27 19:09:47 +03:00
b5ec3e597e
The implementation was ported from `musl`. Unit tests for `f80` and `f128` were also added. The changes were tested by running: ``` $ ./build/stage3/bin/zig build -p stage4 -Denable-llvm -Dno-lib $ stage4/bin/zig build test-libc -Dlibc-test-path=<LIBC-TEST-PATH> -Dtest-filter=sinl -fqemu -fwasmtime --summary line Build Summary: 553/553 steps succeeded ```
38 lines
1.1 KiB
Zig
38 lines
1.1 KiB
Zig
const std = @import("std");
|
|
|
|
pub const U80 = std.meta.Int(.unsigned, 80);
|
|
/// pi divided by 4
|
|
pub const pi_4 = 0.78539816339744830962;
|
|
|
|
/// Returns the sign + exponent bits of a `long double`
|
|
pub fn ldSignExponent(x: anytype) u16 {
|
|
const T = @TypeOf(x);
|
|
switch (T) {
|
|
f80 => {
|
|
const bits: U80 = @bitCast(x);
|
|
return @intCast(bits >> 64);
|
|
},
|
|
f128 => {
|
|
const bits: u128 = @bitCast(x);
|
|
return @intCast(bits >> 112);
|
|
},
|
|
else => @compileError("`ldSignExponent` supports only `f80` and `f128`, got: " ++ @typeName(T)),
|
|
}
|
|
}
|
|
|
|
/// Takes the top 16 bits of a `long double`'s mantissa
|
|
pub fn ldMantissaTop(x: anytype) u16 {
|
|
const T = @TypeOf(x);
|
|
switch (T) {
|
|
f80 => {
|
|
const bits: U80 = @bitCast(x);
|
|
return @intCast((bits >> 48) & 0xFFFF);
|
|
},
|
|
f128 => {
|
|
const bits: u128 = @bitCast(x);
|
|
return @intCast((bits >> 96) & 0xFFFF);
|
|
},
|
|
else => @compileError("`ldMantissaTop` supports only `f80` and `f128`, got: " ++ @typeName(T)),
|
|
}
|
|
}
|