We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
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 explicitly define "round to nearest" behaviour, but it seems to be ignored.
Even worse, FLT_ROUNDS in float.h is defined as floats are rounded, but they're truncated.
fpgetround() and fpsetround() do not work right either.
Any ideas?
See the C programming language standard section 6.3.1.4 Real floating and integer in
http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1124.pdf
The bit you were reading is about rounding of the results of arithmetic operations on floating point values (and it should have referred to round to nearest or even not just round to nearest). For instance when two floating point values are added the exact result might occupy too many bits of precision so it needs to be rounded to a representable value e.g. if we had a machine which had 3 significant places of decimal in its floats 1.37 and 0.356 added would give 1.73 after automatic rounding. However assigning 1.73 to an integer would give 1 as the result.
OK - understood. I've mixed up something. Now it all makes sense. Thanks for clarification!