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
It's been a long time since I've seen a system that didn't support IEEE 754 format. As I recall, endianness is up to the implementation, though.
"endianness is up to the implementation, though." Yes, that's what I was thinking of! A PC might well use more bits, too...
The problem i am facing is that the val4 = sqrt(val4*val4 + val3*val3) is some time not comming correct It couldn't be that you expect a PC and a '51 to come up with identical (+-0.000%) values? could it? Erik
This "Problem" has also been posted on the AVRfreaks forum: http://www.avrfreaks.net/index.php?name=PNphpBB2&file=viewtopic&p=240980#240980 So either the system actually includes an AVR, a PC, and some other Keil-supported processor (8051, ARM, or C166), or the OP is just randomly spamming forums...
yes the whole system involves avr and 8051 so the message is on other forum some things to clear -: The compiler used is c51 -: Application is basically decoding the Latitude and longitude comming inside the micro in four byte format representing a single precesion float -: I had no other option for micro as the hardware is fixed and miro is also fixed for the customer and i am just trying to solve their problems(this one among thelast one). worst they have done all the manufacturing of PCB for production !!
I posted: "It couldn't be that you expect a PC and a '51 to come up with identical (+-0.000%) values? could it?" Give some examples of "wrong" and what it should be Erik