LOGBOOK

HELP

Quiz Entry - updated: 2026.11.27

On the ESP32, why should performance-critical code use float rather than double?

The ESP32's FPU handles single precision only. Every double operation is emulated in software, which is far slower than the one-instruction float version.

A floating-point unit is one of the options a chip designer can select, and Espressif chose the single-precision one. A float multiply therefore compiles to one FPU instruction. A double multiply compiles to a call into a software library routine that does the job with integer instructions, many times slower.

The trap is that C makes double the default without anyone asking for it:

  • A literal such as 0.1 is a double; 0.1f is a float.
  • sqrt(), sin() and friends take and return double; sqrtf() and sinf() are the float versions.
  • float x = y * 0.1; promotes y to double, multiplies in software, then converts back.

So in a sensor loop that runs thousands of times a second, writing 0.1f and sinf() can make a large difference. (The compiler can sometimes narrow a double operation back to float when the result is provably identical, but you shouldn't count on it.) Where you genuinely need 15 significant digits, double still works, just slowly.

Tip: On the ESP32, a bare decimal literal like 0.1 in float code can be a hidden software call; put an f on it.

Go deeper:

From Quiz: SIOT / Xtensa LX6 Registers, Calls and Branches in Assembly | Updated: Nov 27, 2026