Files
zig/lib/compiler_rt/math_utils.zig
T
mihael b5ec3e597e libzigc/math: Implement more precise sinl in compiler_rt
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
```
2026-04-02 23:54:20 +02:00

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)),
}
}