AnsweredAssumed Answered

Float to integer rounding on PowerPC

Question asked by Etienne Alepins on Nov 5, 2015
Latest reply on Nov 13, 2015 by Etienne Alepins

Hi,

 

We've used "efsctsi" assembly instruction on MPC5xxx MCU and "fctiw" on MPC83xx PowerQUICC II Pro CPU (having SPEFSCR[FRMC] / FPSCR[RN] = 00 (round to nearest)) and we were surprised of the result. We were expecting the following 32bits floats to be converted to the following integers:

. 6.5 -> expected=7 ; obtained=6

. 7.5 -> expected=8 (obtained that)

. 8.5 -> expected=9 ; obtained=8

. -6.5 -> expected = -7 ; obtained = -6

. -7.5 -> expected = -8 (obtained that)

. -8.5 -> expected = -9 ; obtained = -8

 

So, is it possible to use these instructions to round floats to integer including round +x.5 to x+1 and -x.5 to -x-1? Or are these instructions performing a base-2 rounding rather than a base-10 rounding?

 

Thanks.

Outcomes