Reference.Float History

Show minor edits - Show changes to markup

November 04, 2013, at 08:36 AM by Scott Fitzgerald -
Added lines 13-14:

If doing math with floats, you need to add a decimal point, otherwise it will be treated as an int. See the Floating point constants page for details.

March 31, 2010, at 06:17 PM by David A. Mellis -
Changed lines 7-8 from:

Floats have only 6-7 decimal digits of precision. That means the total number of digits, not the number to the right of the decimal point. On most platforms you can get more precision by using a double. But even those have limited precision, typically 15 digits. But, on the arduino, doubles are the same size as floats.

to:

Floats have only 6-7 decimal digits of precision. That means the total number of digits, not the number to the right of the decimal point. Unlike other platforms, where you can get more precision by using a double (e.g. up to 15 digits), on the Arduino, double is the same size as float.

March 29, 2010, at 09:18 PM by Tom Igoe -
Changed lines 6-8 from:
to:

Floats have only 6-7 decimal digits of precision. That means the total number of digits, not the number to the right of the decimal point. On most platforms you can get more precision by using a double. But even those have limited precision, typically 15 digits. But, on the arduino, doubles are the same size as floats.

June 25, 2009, at 01:05 PM by Paul Badger -
Added line 40:
  • Variable Declaration
May 13, 2009, at 06:37 AM by Paul Badger -
Added lines 36-39:

See Also

May 13, 2009, at 06:34 AM by Paul Badger -
Changed lines 33-36 from:

Programming Tip

Serial.println() truncates floats (throws away the fractions) into integers when sending serial. Multiply by power of ten to preserve resolution.

to:

November 02, 2008, at 11:32 AM by David A. Mellis -
Deleted lines 10-12:

That being said, floating point math is useful for a wide range of physical computing tasks, and is one of the things missing from many beginning microcontroller systems.

May 29, 2007, at 05:24 AM by David A. Mellis -
Changed lines 7-8 from:

Floating point math is much slower than integer math in performing calculations, so should be avoided if, for example, a loop has to run at top speed for a critical timing function. Programmers often go to some lengths to convert floating point calculations to integer math to increase speed.

to:

Floating point numbers are not exact, and may yield strange results when compared. For example 6.0 / 3.0 may not equal 2.0. You should instead check that the absolute value of the difference between the numbers is less than some small number.

Floating point math is also much slower than integer math in performing calculations, so should be avoided if, for example, a loop has to run at top speed for a critical timing function. Programmers often go to some lengths to convert floating point calculations to integer math to increase speed.

May 29, 2007, at 03:08 AM by Paul Badger -
Changed line 31 from:
   y = x / 2;   // y now contains 0, integers can't hold fractions
to:
   y = x / 2;            // y now contains 0, ints can't hold fractions
April 17, 2007, at 12:05 AM by David A. Mellis -
Changed lines 17-18 from:

Parameters

to:

Syntax

April 16, 2007, at 06:38 PM by Paul Badger -
Changed lines 26-33 from:

int x; int y; float z;

x = 1; y = x / 2; // y now contains 0, integers can't hold fractions z = (float)x / 2.0; // z now contains .5 (you have to use 2.0, not 2)@]

to:
   int x;
   int y;
   float z;

   x = 1;
   y = x / 2;   // y now contains 0, integers can't hold fractions
   z = (float)x / 2.0;   // z now contains .5 (you have to use 2.0, not 2)@]
April 16, 2007, at 06:36 PM by Paul Badger -
Deleted line 37:
April 14, 2007, at 10:14 PM by Paul Badger -
Changed lines 32-33 from:

z = x / 2.0; // z now contains .5 (you have to use 2.0, not 2)@]

to:

z = (float)x / 2.0; // z now contains .5 (you have to use 2.0, not 2)@]

April 14, 2007, at 06:01 PM by David A. Mellis - correcting float = int / int; to float = int / float;
Changed lines 32-33 from:

z = x / 2; // z now contains .5@]

to:

z = x / 2.0; // z now contains .5 (you have to use 2.0, not 2)@]

April 14, 2007, at 07:06 AM by Paul Badger -
Changed line 9 from:

That being said, floating point math is one of the things missing from many beginning microcontroller systems.

to:

That being said, floating point math is useful for a wide range of physical computing tasks, and is one of the things missing from many beginning microcontroller systems.

Changed lines 22-24 from:
  • val - the value you assign to that variable

to:
  • val - the value you assign to that variable

Example Code

int x;
int y;
float z;

x = 1;
y = x / 2;   // y now contains 0, integers can't hold fractions
z = x / 2;   // z now contains .5

Programming Tip

Serial.println() truncates floats (throws away the fractions) into integers when sending serial. Multiply by power of ten to preserve resolution.

April 14, 2007, at 06:54 AM by Paul Badger -
Changed lines 14-15 from:
 float myfloat;

float sensorCalbrate = 1.117;

to:
    float myfloat;
    float sensorCalbrate = 1.117;
April 14, 2007, at 06:51 AM by Paul Badger -
Changed lines 7-9 from:

Floats are much slower than integers to perform calculations with, so should be avoided if, for example, a loop has to run at top speed for a critical timing function.

to:

Floating point math is much slower than integer math in performing calculations, so should be avoided if, for example, a loop has to run at top speed for a critical timing function. Programmers often go to some lengths to convert floating point calculations to integer math to increase speed.

That being said, floating point math is one of the things missing from many beginning microcontroller systems.

Changed lines 18-20 from:
    int var = val;

  • var - your int variable name
to:
    float var = val;

  • var - your float variable name
Deleted lines 23-26:

April 14, 2007, at 06:43 AM by Paul Badger -
Added lines 1-26:

float

Description

Datatype for floating-point numbers, a number that has a decimal point. Floating-point numbers are often used to approximate analog and continuous values because they have greater resolution than integers. Floating-point numbers can be as large as 3.4028235E+38 and as low as -3.4028235E+38. They are stored as 32 bits (4 bytes) of information.

Floats are much slower than integers to perform calculations with, so should be avoided if, for example, a loop has to run at top speed for a critical timing function.

Examples

 float myfloat;

float sensorCalbrate = 1.117;

Parameters

    int var = val;

  • var - your int variable name
  • val - the value you assign to that variable

Reference Home

Share