This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Rounding floats to integers on Cortex-M4

I've encountered an odd problem on STM32F4xx CPU with hardware FPU enabled:

When rounding floats to integers, compiler always uses VCVT (round towards zero) instruction
instead of VCVTR (round using rounding mode register settings).

There are compiler options for various IEEE compatibility modes, some of them explicitely
define "round to nearest" behaviour, but it seems to be ignored.

Any ideas?

  • Oh, yes, to make it more fun - compiler-defined constant FLT_ROUNDS indicates (wrongly) that float-to-integer conversion rounds, although it truncates the value.

    fgetround() call returns right contents of FPU rounding mode, but compiler does not use the right instruction, so it does not matter anyway...