implement all the math functions for all the floating point types
Boxes without check marks do not have test coverage.
| f16 | f32 | f64 | f128 | c_longdouble | |
|---|---|---|---|---|---|
@sqrt |
✓ | ✓ | ✓ | ||
@sin |
✓ | ✓ | ✓ | ||
@cos |
✓ | ✓ | ✓ | ||
@exp |
✓ | ✓ | ✓ | ||
@exp2 |
✓ | ✓ | ✓ | ||
@ln |
✓ | ✓ | ✓ | ||
@log2 |
✓ | ✓ | ✓ | ||
@log10 |
✓ | ✓ | ✓ | ||
@fabs |
✓ | ✓ | ✓ | ||
@floor |
✓ | ✓ | ✓ | ||
@ceil |
✓ | ✓ | ✓ | ||
@trunc |
✓ | ✓ | ✓ | ||
@nearbyInt |
|||||
@round |
I've just come across a need for exp and ln with f128, so I'm going to take a look at this :)
I haven't got anywhere with implementations yet, but I've learnt a lot about how floats work and implementations of the exp2() function. I'm making notes and will track progress at https://github.com/LewisGaul/zig-f128math (taking inspiration from the initial work by @tiehuis in https://github.com/tiehuis/zig-fmath).
Mainly leaving this comment in case useful to anyone else interested in working on this.
I do also have a question about c_longdouble (since it's included in the table above). Quoting from https://github.com/tiehuis/zig-fmath/issues/7:
The
c_longdoubletype is not implemented at all. The rationale is if required, the user should use thelibcmath library, which makes some sense given it is a c abi type anyway. The long double functions as well generally are more complex to implement as well.
Is there a reason this can't just map to f128? The C standard just says that long double must be at least as accurate as double I believe. The Musl implementation modifies its behaviour based on LDBL_MANT_DIG and LDBL_MAX_EXP macros (https://www.gnu.org/software/libc/manual/html_node/Floating-Point-Parameters.html), would we need to do something like respect those parameters when interpreting a c_longdouble?
Is there a reason this can't just map to
f128? The C standard just says thatlong doublemust be at least as accurate asdoubleI believe. The Musl implementation modifies its behaviour based onLDBL_MANT_DIGandLDBL_MAX_EXPmacros (https://www.gnu.org/software/libc/manual/html_node/Floating-Point-Parameters.html), would we need to do something like respect those parameters when interpreting ac_longdouble?
I now realise that it seems C uses 80-bit extended precision rather than the IEEE-754 128-bit standard, and presumably support for this might be required for interop with C...
@nearbyInt doesn't seem to exist in the language anymore
I'm fairly new to contributing to open-source projects, but I may give this a shot as Zig's been a very interesting project to keep an eye on. No promises, but I will do my best :D
Done in #11532