Go Down

Topic: Manipulating IEEE754 32bit floats (incl mapping 64bit double) (Read 1 time) previous topic - next topic

robtillaart

Sep 08, 2013, 11:48 am Last Edit: Sep 08, 2013, 02:35 pm by robtillaart Reason: 1
After a discussion about exporting a 64bit double from Arduino to some PC application here - http://forum.arduino.cc/index.php?topic=186674.0 - I transformed the prototype code I posted into something more manageable and create a playground page for it.

Today I created an initial version of the page here - http://playground.arduino.cc//Main/IEEE754tools - and it will be 'completed' asap.

As always remarks, additions and comments are welcome.

update1: fixed code in .h file
update2: added Arduino sender + Python receiver
updateN: added Arduino echo application + Python send/receive
Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

pito

I think arduino needs a 64bit double to be fully implemented. Long time back I did with IAR for AVR which supports double and the double math is (only) 2x slower as the 32bit what would be fully acceptable..

robtillaart

Quote
I think arduino needs a 64bit double to be fully implemented.

It is often asked for, but have seen no code yet...
There are not so much sensors that give more significant digits than a float can handle. Note that 6 significant digits means a dynamic range of a factor 100000.

Why do you need doubles?
Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

robtillaart

#3
Sep 08, 2013, 06:12 pm Last Edit: Sep 08, 2013, 07:47 pm by robtillaart Reason: 1
For next version of the IEEE754tools I am creating faster tests for isNAN and isINF.
Code: [Select]
bool IEEE_NAN(float number)  
{
   return (* ((uint16_t*) &number + 1) ) == 0x7FC0;
}

bool IEEE_INF(float number)  
{
   return (* ((uint16_t*) &number + 1) ) == 0x7F80;
}

bool IEEE_NegINF(float number)  
{
   return (* ((uint16_t*) &number + 1) ) == 0xFF80;
}


IEEE_NAN() is ~1.9x faster than isnan()
IEEE_INF() is ~4.0x faster than isinf() but the interface is different            // factor updated after new measurement

to be continued...
Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

robtillaart

Code: [Select]

int IEEE_INF(float number) 
{
    uint16_t* x = ((uint16_t*) &number + 1);
    // if ((*x & 0x7F80) != 0x7F80) return 0;
    if (*x == 0x7F80) return 1;
    if (*x == 0xFF80) return -1;
    return 0;
}


on average of the 3 code paths is almost ~3.3x faster than isinf()    (normal numbers 3.1x)
if the extra line is added the average is ~3.0x faster  (normal numbers 3.3x). As most numbers are normal this might be the preferred version.
so these are slower than the dedicated versions.
==> just add them all, so the user has the choice, (linker will optimize anyway).
Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Go Up