floating-pointrustrounding

Can the floating point rounding mode be set at compile time in Rust?


I want to play with interval arithmetic in Rust, and to do so I need to set the rounding mode upward or downward. As I understand from some searching, setting the rounding mode will affect the performance, so I'd want to set it at compile time.


Solution

  • Not reliably, no. The problem is that the LLVM backend doesn't provide any support for modifying the rounding mode, though recently there have been some proposals to fix this, it's not likely to be resolved in the near future.

    You might be able to call out to the C fesetround function (in fenv.h) at the start of your program, but the problem is that certain optimisations (such as constant folding) would have already been performed using the default rounding mode.