Go Down

### Topic: Floating point format (Read 2802 times)previous topic - next topic

#### jfhaugh

##### Oct 09, 2011, 06:41 pm
What's the binary format for the floating point data type?

#### robtillaart

#1
##### Oct 09, 2011, 06:57 pm

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

#2
##### Oct 09, 2011, 07:28 pm

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

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

#### fat16lib

#3
##### Oct 09, 2011, 08:33 pm
Arduino is little endian.  The float and double types are both 32-bit IEEE floating point.

#### jfhaugh

#4
##### Oct 10, 2011, 01:13 am

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

#5
##### Oct 10, 2011, 06:55 am

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 optimizevolatile 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

#6
##### Oct 13, 2011, 07:42 am
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

#7
##### Oct 14, 2011, 07:58 pm
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