Tag Archives: float

Lean and Mean Float to String Conversion (ftoa)

Here is an often requested, basic float to ascii conversion function (ftoa). The typical method for arduino to perform this conversion is to use either of the dtostrf() or sprintf() functions. Both of these library functions incorporate the same underlying … Continue reading

Posted in Uncategorized | Tagged , , , , , , , , | Leave a comment

Floating Point Precision and Binary 32 or, Arduino Don’t Know Math

Did you know? 0.1 + 0.2 = 0.30000001 Try this simple arduino program to prove it: First, don’t be alarmed, and second, don’t throw your arduino into the trash thinking it’s defective. Its working just fine. For comparison, performing this … Continue reading

Posted in Uncategorized | Tagged , , , , | Leave a comment

Convert an ASCII String to Fixed Point: atofp()

Here is a small utility routine which converts an ASCII string floating point number into an s16.15 format fixed point number. Most fixed point libraries neglect this conversion. However, in practice, this routine is very useful. If the conversion process … Continue reading

Posted in Uncategorized | Tagged , , , , | 2 Comments

Arduino s16.15 Fixed Point Math Routines

It is important to note, that fixed point math comes in many flavors. For example, a 16-bit integer can implement 31 different fixed point formats, signed and unsigned Q1 through Q16 (Q number format). A couple of popular 16-bit formats … Continue reading

Posted in Uncategorized | Tagged , , , , , , , , , , , , , , | Leave a comment

Converting a Float to a Char Array

Surprisingly, this question pops up often. While the technique used here is not really a conversion, it does allow access to the individual byte values of a float variable by constructing a union. A union is a data structure that … Continue reading

Posted in Uncategorized | Tagged , , | Leave a comment

Continued Look at Fixed Point Math on the Arduino Platform

Continuing my overly simplified comparison of 24.8 fixed point vs. floating math on the AVR168/328 chip, I compared the elapsed time of the following two division operations running at 16Mhz: That’s nearly 1.8 times faster for the fixed-point math. If … Continue reading

Posted in Uncategorized | Tagged , , , , , | 3 Comments

Fixed Point Math on the Arduino Platform

Here is an overly simplified comparison of 24.8 fixed point vs. floating math on the AVR168/328 chip. I compared the elapsed time of the following two multiplications running at 16Mhz: That’s nearly 9.5 times faster. However, my comparison is not … Continue reading

Posted in Uncategorized | Tagged , , , , , | 11 Comments