AnsweredAssumed Answered

Bad division computation on MPC560xB

Question asked by Romain BENET on Aug 1, 2016
Latest reply on Aug 1, 2016 by Martin Kovar



I use a MPC560xB microcontroller and I have found an error of a division computation.


This is an example:


/** Data declaration */

signed int s32A;

unsigned int u32B;

signed int s32Result;


/** Data computation */

s32A = -30;

u32B = 30;

s32Result = s32A / s32B

Value for s32Result using debugger is 143165575. This is not the expected value (expected value is -1).


The computation [unsigned value] / [unsigned value] gives the expected result,

the computation [signed value] / [signed value ] gives the expected result

the computation [signed value] / [unsigned value] or [unsigned value] / [signed value] gives a unexpected result (choosen type by the compiler is unsigned instead of signed).



Thanks for your help.

Romain BENET