Home/Support/Support Forum/Double precision float - Incorrect Format!
Welcome to Digi Forum, where you can ask questions and receive answers from other members of the community.

Double precision float - Incorrect Format!

0 votes
cc9P9215 double precision floating point number problem.
So that those of you out there don't spend a week tearing your hair out over this problem here you go. The digi double precision floating point representation does NOT follow IEEE 754 recommendations. Therefore when communicationg doubles outside of the system it is necessary to do additional byte swapping (in addition to the normal hton or ntoh swap) The Digi representation is in the following order;
Byte Number from IEEE754 [0] to [7], Digi [4][5][6][7][0][1][2][3]. Once you know it is easy to accomodate, see below;

double ntohd(char* netDoubleIn){ //provide pointer to input array

char* tmpDbl;
double retVal;

tmpDbl = (char*)&retVal;
tmpDbl[0] = netDoubleIn[3];
tmpDbl[1] = netDoubleIn[2];
tmpDbl[2] = netDoubleIn[1];
tmpDbl[3] = netDoubleIn[0];
tmpDbl[4] = netDoubleIn[7];
tmpDbl[5] = netDoubleIn[6];
tmpDbl[6] = netDoubleIn[5];
tmpDbl[7] = netDoubleIn[4];

return(retVal);
}

Hope this helps someone, feedback always appreciated. [:)]
ps: don't forgot you need to do the same swap for a hton
asked Jan 1, 2012 in NET+OS by digiDave New to the Community (20 points)
recategorized Jun 17, 2013 by mcarver

Please log in or register to answer this question.

...