Skip to content

Commit

Permalink
Merge pull request #864 from Core-l/patch-1
Browse files Browse the repository at this point in the history
Strange results in floating point
  • Loading branch information
per1234 authored Aug 13, 2022
2 parents f0431be + d74e42b commit ac98490
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion Language/Variables/Data Types/float.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ If doing math with floats, you need to add a decimal point, otherwise it will be

The float data type has 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.

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 numbers are not exact, and may yield strange results when compared. For example 9.0 / 0.3 may not quite equal 30.0. You should instead check that the absolute value of the difference between the numbers is less than some small number.

Conversion from floating point to integer math results in truncation:
[source,arduino]
Expand Down

0 comments on commit ac98490

Please sign in to comment.