zig icon indicating copy to clipboard operation
zig copied to clipboard

implement all the math functions for all the floating point types

Open andrewrk opened this issue 6 years ago • 5 comments

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

andrewrk avatar Jan 02 '20 02:01 andrewrk

I've just come across a need for exp and ln with f128, so I'm going to take a look at this :)

LewisGaul avatar Aug 21 '21 11:08 LewisGaul

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_longdouble type is not implemented at all. The rationale is if required, the user should use the libc math 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?

LewisGaul avatar Aug 23 '21 23:08 LewisGaul

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?

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...

LewisGaul avatar Nov 02 '21 21:11 LewisGaul

@nearbyInt doesn't seem to exist in the language anymore

ghost avatar Oct 19 '22 07:10 ghost

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

Jess4Tech avatar Nov 01 '22 18:11 Jess4Tech

Done in #11532

Vexu avatar Dec 28 '22 13:12 Vexu