Implemented functions:
lrintf
rintf
lrint
finite
finitef
frexp
frexpf
frexpl
Implemented more precise/correct versions in compiler_rt:
Tests were run at each commit and results, as well as more info, are included with every commit.
Other than the implementations, there's two things I'd point out:
- The only exception to testing are
finite/finitef functions since there are no tests for them in libc-test. However, these are very straightforward and obsolete, anyways. But musl still has them.
rint tests were re-enabled since the respective libc-test tests are passing now when using the Zig-native implementation.
Contributes to #30978
I've noticed that the fpu exception functions in std.math are no-ops, and git blame tells me they haven't been touched in 8 years. I'm not sure what the plans are, but if we want a libzigc, we'll need the ability to manipulate them.
For example, the nearbyint acts exactly like rint, except it mustn't raise the INEXACT exception -- which means we need to be able to clear the flag in the code if that happens.
Musl implementation:
double nearbyint(double x)
{
#ifdef FE_INEXACT
#pragma STDC FENV_ACCESS ON
int e;
e = fetestexcept(FE_INEXACT);
#endif
x = rint(x);
#ifdef FE_INEXACT
if (!e)
feclearexcept(FE_INEXACT);
#endif
return x;
}
For this reason, nearbyint tests in libc-test are failing now.
As another example, if I enable llrint tests, I get a bunch of errors about a missing INVALID exception:
bad fp exception: RN llrint(nan)=0, want INVALID got 0
bad fp exception: RN llrint(inf)=0, want INVALID got 0
bad fp exception: RN llrint(-inf)=0, want INVALID got 0
bad fp exception: RN llrint(0x1p+100)=0, want INVALID got 0
bad fp exception: RN llrint(-0x1p+100)=0, want INVALID got
We should probably raise the INVALID exception on these arguments in the rint function, if we had the support for it.
Ultimately, adding support for managing the floating point environment also works towards #30978, because we're the reimplementing the musl's fenv module.
I'd try tackling this (I'd reuse the assembly code from musl), but I'm not sure what the plans are regarding this. Obviously, there was intent to do something about it. Or maybe it's already done and I just missed it somewhere in the docs? :D
I'd try adding support for handling these exceptions to Zig's std, then wrap it in libzigc, and then use them as needed elsewhere.
Implemented functions:
- `lrintf`
- `rintf`
- `lrint`
- `finite`
- `finitef`
- `frexp`
- `frexpf`
- `frexpl`
Implemented more precise/correct versions in `compiler_rt`:
- `cosl`
- `sinl`
- `tanl`
- `sincosl`
Tests were run at each commit and results, as well as more info, are included with every commit.
Other than the implementations, there's two things I'd point out:
- The only exception to testing are `finite`/`finitef` functions since there are no tests for them in `libc-test`. However, these are very straightforward and obsolete, anyways. But `musl` still has them.
- `rint` tests were re-enabled since the respective `libc-test` tests are passing now when using the Zig-native implementation.
Contributes to #30978
<hr>
<hr>
I've noticed that the [fpu exception functions in `std.math`](https://codeberg.org/ziglang/zig/blame/branch/master/lib/std/math.zig#L179) are no-ops, and git blame tells me they haven't been touched in 8 years. I'm not sure what the plans are, but if we want a `libzigc`, we'll need the ability to manipulate them.
For example, the `nearbyint` acts exactly like `rint`, except it mustn't raise the `INEXACT` exception -- which means we need to be able to clear the flag in the code if that happens.
Musl implementation:
```c
double nearbyint(double x)
{
#ifdef FE_INEXACT
#pragma STDC FENV_ACCESS ON
int e;
e = fetestexcept(FE_INEXACT);
#endif
x = rint(x);
#ifdef FE_INEXACT
if (!e)
feclearexcept(FE_INEXACT);
#endif
return x;
}
```
For this reason, `nearbyint` tests in `libc-test` are failing now.
As another example, if I enable `llrint` tests, I get a bunch of errors about a missing `INVALID` exception:
```
bad fp exception: RN llrint(nan)=0, want INVALID got 0
bad fp exception: RN llrint(inf)=0, want INVALID got 0
bad fp exception: RN llrint(-inf)=0, want INVALID got 0
bad fp exception: RN llrint(0x1p+100)=0, want INVALID got 0
bad fp exception: RN llrint(-0x1p+100)=0, want INVALID got
```
We should probably raise the `INVALID` exception on these arguments in the `rint` function, if we had the support for it.
Ultimately, adding support for managing the floating point environment also works towards #30978, because we're the reimplementing the `musl`'s `fenv` module.
I'd try tackling this (I'd reuse the assembly code from `musl`), but I'm not sure what the plans are regarding this. Obviously, there was intent to do something about it. Or maybe it's already done and I just missed it somewhere in the docs? :D
I'd try adding support for handling these exceptions to Zig's std, then wrap it in `libzigc`, and then use them as needed elsewhere.