 # Noob question about floating point constants

Hi everybody,

as a one week old arduino programmer i try to lean all the references on the Arduino website.

But I’m stuck at the reference about floating point constants. I find the explanation a bit minimal and don’t understand the use from them besides that you can make other notations.

but for example how are they stored? as an int, a double…
what about decimal point because only floats can hold them
and can someone give me an example how they are used?

thanks in advance

best regards

jazzy

``````float first;
float second, third;
float pi = 3.1415;
..
second = 4.556e-13;
first = pi * second;
``````

All floats are single precision, 32bit, stored as 4 bytes.

but for example how are they stored? as an int, a double...

As a float.

what about decimal point because only floats can hold them

No. Doubles, long doubles, etc., can also store non-integral values.

and can someone give me an example how they are used?

``````float PI = 3.14159;
``````

Arduino uses IEEE 754 floating point format. Note, the AVR gcc compiler only uses the 32-bit single precision format, so float and double share the same format. The ARM gcc compiler for the Due/teensy 3.0/mbed/beaglebone/Rasberry-Pi defines double as 64-bit IEEE 754. Here is the Wikipedia entry on IEEE 754: IEEE 754 - Wikipedia

Note, that none of the AVRs, nor the Due/Teensy 3.0 support floating point in hardware. All floating point is done by software emulation. Larger chips do support 32/64-bit in hardware (and occasionally 80 or 128-bit).

``````float PI = 3.14159;
``````

That is a very sneaky answer Paul. True, that is an example of how it is used, but would it compile in a user's program ?

``````float myPI = 3.14159;
``````

does

jazzygerard: Hi everybody,

as a one week old arduino programmer i try to lean all the references on the Arduino website.

But I'm stuck at the reference about floating point constants. I find the explanation a bit minimal and don't understand the use from them besides that you can make other notations.

but for example how are they stored? as an int, a double... what about decimal point because only floats can hold them and can someone give me an example how they are used?

thanks in advance

best regards

jazzy

I am not entirely sure it you are talking about floating point literals (floating values written numerically in code) or floating point variables that are declared "const"?

These days all processors store floating point values in IEEE format as mentioned previously, wikipedia will have all the gory details if you want them.

Ok guys,

thanks for all the replies.

best regards

jazzy