The most simple way to get fmod?


#1

I need analog of fmod function from standard C library, for things like:

rads = fmod(rads, 2. * PI);

I can not find analog in rust std, so I try external libc crate, but it does not wrap math part of libc.
So I should write

use libc::c_double;

#[link_name = "m"]
extern {
  fn fmod(a: c_double, b: c_double) -> c_double;
}

and make my code not portable, or there is more good way to get fmod to rust code?


#2

Try:

fn main() {
    let mut rads = 5.0;
    rads %= 2.0 * std::f64::consts::PI;
}

#3

Thanks you, it works exactly like fmod