Pages: [1]   Go Down
Author Topic: Floating point format  (Read 1226 times)
0 Members and 1 Guest are viewing this topic.
Austin, TX
Offline Offline
Full Member
***
Karma: 0
Posts: 134
I make my own electricity.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Global Moderator
Netherlands
Offline Offline
Shannon Member
*****
Karma: 168
Posts: 12430
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset


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

Rob Tillaart

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

Austin, TX
Offline Offline
Full Member
***
Karma: 0
Posts: 134
I make my own electricity.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset


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

0
Offline Offline
Edison Member
*
Karma: 44
Posts: 1471
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Austin, TX
Offline Offline
Full Member
***
Karma: 0
Posts: 134
I make my own electricity.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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."?
Logged

Global Moderator
Netherlands
Offline Offline
Shannon Member
*****
Karma: 168
Posts: 12430
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset


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:
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);
Logged

Rob Tillaart

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

Austin, TX
Offline Offline
Full Member
***
Karma: 0
Posts: 134
I make my own electricity.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Global Moderator
Netherlands
Offline Offline
Shannon Member
*****
Karma: 168
Posts: 12430
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.



Logged

Rob Tillaart

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

Pages: [1]   Go Up
Jump to: