sletz
April 2, 2024, 2:15pm
1
We generate this code:
mod ffi {
use std::os::raw::{c_float};
#[link(name = "m")]
extern {
pub fn remainderf(from: c_float, to: c_float) -> c_float;
pub fn rintf(val: c_float) -> c_float;
}
}
fn remainder_f32(from: f32, to: f32) -> f32 {
unsafe { ffi::remainderf(from, to) }
}
fn rint_f32(val: f32) -> f32 {
unsafe { ffi::rintf(val) }
}
to have the missing remainderf
and rintf
. But this does not compile on Windows which does not have "m" libray. How to solve that ?
1 Like
farnz
April 2, 2024, 2:41pm
2
rint
is f32::round
.
I can't find remainderf
equivalents, but Analog of c++ std::remainder? suggests that it's easy to implement yourself with what Rust provides, and that asking for it via a Rust language issue might get you a solution in a later version of Rust, since it's an IEEE 754 requirement.
sletz
April 2, 2024, 2:44pm
3
I'm not sure:
man rint gives:
The rint() functions return the integral value nearest to x (according to the prevailing rounding mode ) in floating-point format.
The round() functions return the integral value nearest to x rounding half-way cases away from zero, regardless of the current rounding direction .
And Analog of c++ std::remainder? does not give a proper final answer AFAICS.
farnz
April 2, 2024, 3:16pm
4
The current rounding direction in Rust is always "roundTiesToEven", so you maybe want f32::round_ties_even
instead of f32::round
.
system
Closed
July 1, 2024, 3:17pm
5
This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.