I'm pretty new to Rust but AFAICT the basic issue I'm having is that core::primitive::[f32|f64] doesn't expose the methods defined in std::primitive... and I have two main questions:
Is there a workaround? It would be nice to avoid having to define my own basic arithmetic utilities.
Why? core::primitive::u32, for example, does include similar utilities, even experimental ones like div_floor (which I also use).
I'm working on a bare-metal library with the following cargo config:
error[E0599]: no method named `ceil` found for type `f32` in the current scope
--> libboard_zynq_us/src/ddr/spd.rs:445:62
|
445 | (time_ps as f32 / self.t_ckavg_min_ps as f32 - 0.01).ceil() as u32
| ^^^^ method not found in `f32`
This isn't what you're asking, but you can do ceiling division with integers. If everything is positive it's just (x + y - 1) / y. I don't know how integer division performs on your hardware but the code in libm looks like it could pretty inefficient (since it has to be written portably). For floating point there are techniques for converting to integers that typically require adding and subtracting a special constant (2^52 for nonnegative f64 values) though how to get the ceiling is contingent on the rounding mode.
Yeah, it occurred to me that for this specific calculation I could do it with integers (albeit in a way that doesn't look much like the spec I'm taking the formula from), but I figured I'd ask the question anyway since I have a hard FPU and I'm going to want to use it eventually. Thanks!