# Math operation

Hi there,

I have a piece of code for a linear interpolation:

uint32_t resTMR1=0;

int32_t temp_ACQ=0;

temp_ACQ1= ( ( ( (resTMR1-POLS_TEMP_MINUS30)*100) / (POLS_TEMP_MINUS20-POLS_TEMP_MINUS30 ) )* (TEMP_MINUS20-TEMP_MINUS30) ) + (TEMP_MINUS30*100) ;

resTMR1 contains the pulses generated by an external sensor, I decided to replace the external sensor with a vector with code testing purposes.

uint16_t VECTOR_TEMP_DEBUG[LIMIT_DEBUG]={26,186,338,494,651,808,1125,1284,1923};

expected result: -50,-39,-30 -20, -10, 0, 20, 30, 71

When I check if the results are the expected ones I realize they are not.

So I decide to split the operations in order to check what is going on:

uint32_t resTMR1=0;

int32_t temp_ACQ=0;

int32_t temp_ACQ1=0;

int32_t a;

int16_t d;

uint8_t b,c;

a=((resTMR1-POLS_TEMP_MINUS30 )*100);

b=(POLS_TEMP_MINUS20-POLS_TEMP_MINUS30 );

c=(TEMP_MINUS20-TEMP_MINUS30);

d=(TEMP_MINUS30*100);

temp_ACQ= ( ( a / b )* c ) + d ; (eq.1)

and compare with

temp_ACQ1= ( ( ( (resTMR1-POLS_TEMP_MINUS30)*100) / (POLS_TEMP_MINUS20-POLS_TEMP_MINUS30 ) )* (TEMP_MINUS20-TEMP_MINUS30) ) + (TEMP_MINUS30*100) ; (eq.2)

with (eq.1) results are as expected but with (eq.2) results are always wrong.

I modified the size for temp_ACQ1 from int32_t to int64_t and the results still wrong.

I checked the brackets and seems to be on place, is there any kind of limitation with intermediate results?

what I am doing wrong?

PIC: 16F18324 + pickit 4 + MPLAB IDE X 5.10

Thanks in advance,

Marc