Question on "unspecified precision"

f64::pow{i|f} functions' documentation states

The precision of this function is non-deterministic. This means it varies by platform, Rust version, and can even differ within the same execution from one invocation to the next.

Does this mean that even when passed the same inputs these functions are non-deterministic (ignoring the user changing the hardware rounding mode between executions) or rather that while one set of inputs may result in e.g. 5 ULPs of error while another may give e.g. 3 and Rust gives no upper bound on the ULPs of error?

Yes, even the same inputs can give different outputs. The typical way that happens is that the optimizer will give answers accurate to half-ULP -- the best possible -- but your runtime math library might not be that accurate.

If you're trying to do portably-deterministic floating point, you'll need to use your own math library for everything but +-*/%√.

2 Likes

libm provides pure-Rust floating-point functions, so if all you need is determinism, that'll solve your problems. It doesn't document any guarantees about stability of the results across versions, though.

3 Likes

I'm just computing powers of 10, so this should be trivial to do.Thanks!

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.