Go Down

Topic: Floating point format (Read 1 time) previous topic - next topic

jfhaugh

What's the binary format for the floating point data type?

robtillaart


IEEE754 - http://en.wikipedia.org/wiki/Single_precision_floating-point_format -
Rob Tillaart

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

jfhaugh



IEEE754 - http://en.wikipedia.org/wiki/Single_precision_floating-point_format -


I assume it's big endian on the byte order?

fat16lib

Arduino is little endian.  The float and double types are both 32-bit IEEE floating point.

jfhaugh


Arduino is little endian.  The float and double types are both 32-bit IEEE floating point.


Thanks -- somehow I got it in my head it was a big endian environment.

I figure you have to know the answer to this one, since you seem to be the resident font of all knowledge -- how many flops for an average mix of add, subtract, multiply and divide?  Anyone ever bench mark the floating point, or is the answer "don't do it."?

robtillaart


floating points are expensive (time & footprint) as there is no dedicated hardware for it.

A simple timing sketch with 10000 add (etc) will give you the numbers, snippet code see below

Code: [Select]

volatile float a = 3.14; // volatile prevents compiler optimize
volatile float b = 2.78;
volatile float c = 0;
unsigned long before = millis();
for (int i=0; i< 1000; i++)
{
   c = a * b;
}
Serial.println( miliis() - before);

Rob Tillaart

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

jfhaugh

That would require me to have a spare Arduino to benchmark.  The one and only Uno I have at the moment is currently doing Modbus longevity testing.  I have some MAX485 chips coming to town and will have a proper RS-485 Uno just in time for the handful of Mini's I ordered to arrive.  THEN benchmarking.

robtillaart

OK,

but recall that in the range -2^31 .. 2^31 (~~2.000.000.000)  longs are much faster, and most math that only do math in this range is convertable from float to long. Even if you need e.g. 3 decimals you can do it in long and divide by 1000.0 at the last moment.



Rob Tillaart

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

Go Up