Hello Everybody, Iam facing a strange problem with floats and their mathematical operations i recive a string of data through serial port( 20bytes i.e 5 float values) so to do mathematical operation on these floating values i needto see the raw bytes in floating values to do that i created a union like below union { unsigned char FB[4]; float value; long value1; }convert1; now i use convert1 to use the raw bytes for my calculations like below float val1 = 0; float LAST_val1 = 0; float val2 = 0; float LAST_val2 = 0; float val3 = 0; float val4 = 0; float DIFFERANCE = 0; Get_Difference(){ convert1.FB[0] = BUFFER[0]; convert1.FB[1] = BUFFER[1]; convert1.FB[2] = BUFFER[2]; convert1.FB[3] = BUFFER[3]; val1 = convert1.value; val1 = (val1*180)/PI; val4 = val1 - LAST_val1; LAST_val1 = (convert1.value*180)/PI; convert1.FB[0] = BUFFER[4]; convert1.FB[1] = BUFFER[5]; convert1.FB[2] = BUFFER[6]; convert1.FB[3] = BUFFER[7]; val2 = convert1.value; val2 = (val2*180)/PI; val3 = val2 - LAST_val2; LAST_val2 = (convert1.value*180)/PI; val4 = sqrt(val4*val4 + val3*val3); if( val4 < 0.01) DIFFERANCE = DIFFERANCE + val4; } i am calling the Get_Differance(); function many times in my application The problem i am facing is that the val4 = sqrt(val4*val4 + val3*val3) is some time not comming correct i am also monetring the values on my PC ie.the whole buffer is sent to an application on pc which shows the expected values but not inside the micro is there some thing wrong with squaring of floating point number? should i use a function for that? pls help
Yes the data is sent in correct order because i have simulated it. and there are few values which are not computed correctly the dat i recive from one module is sent as its to the pc as well as to this function so data is comming via micro i am using c51 and micro i am using is 89c52 i have also disabled interrupts in this function thanks and regards
Yes the data is sent in correct order because i have simulated it. and there are few values which are not computed correctly Can you give an example ? i.e. what are the input values, what is the result, and what result did you expect ?
"Yes the data is sent in correct order because i have simulated it." Are you certain that your simulation is correct? "i am using c51 and micro i am using is 89c52" A rather strange choice for a number-cruncher!