Analog of C11 stdlib function nextafter?

I asked question on SO: rust - How can I convert a f64 to f32 and get the closest approximation and the next greater or smaller value? - Stack Overflow

But because of asking about "what crate has suitable functionality" is not approapriate,
I am asking here,
is any crate around that provide functionality similar to nextafter function from stdlib:
https://en.cppreference.com/w/c/numeric/math/nextafter
?

I was gonna say you could just call the C stdlib functions themselves, but it looks like they're not included in the libc crate :confused:.

So you could submit a PR to libc to add them, then call them (if you don't mind using your own fork of libc while you wait for them to get merged/published).

3 Likes

Someone on SO linked you to float_extras::f64::nextafter - Rust (re-linking for those who may end up finding this thread when searching for a similar issue)

You could also temporarily keep a version of the function declaration in your project until it's added to libc, here could be how: Rust Playground

1 Like

These are also relatively easy to implement yourself, using {to|from}_bits.

A starting demonstration: Rust Playground

this is not looks similar to real implementation: libm/src/s_nextafterf.c - platform/bionic - Git at Google

many edge cases missed?

1 Like

It says "starting" for a reason. More obviously, the "demonstration" only has one parameter, not two.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.