Are doubles really doubles on Teensy4.1


New member
I did a simple test on my teensy4.1:

double a = 1.00001; double b = 1.00001;
Serial.printf("a %.16f b %.16f a*b %.16f", a, b, a*b);

and got this result: a 1.0000100135803223 b 1.0000100135803223 a*b 1.0000200272609163

I expected: a 1.000010000 b 1.000010000 a*b 1.000020001

It looks like that the 64 bits doubles are truncated to 32 bits float while reading the numbers in the text.

Any feedback is welcome.

Ad Denissen.
Last edited:
I get the values you expected, as shown below. This is with optimize set to "Faster". Are you using a different setting, such as "Smallest Code"? There has been some discussion of a different printf.

You might also try using format "lf" instead of "f".

a 1.0000100000000001 b 1.0000100000000001 a*b 1.0000200001000001
%lf shouldn't do anything / may not be recognized. %f is already the format specifier for a double, as floats get promoted to doubles when passed to a function that uses variadic arguments.
I am using VS code with with the follow snippet of settings in c_cpp_properties.json:

"defines": [
"cppStandard": "gnu++14",
"compilerPath": "/home/demo/.platformio/packages/toolchain-gccarmnoneeabi/bin/arm-none-eabi-gcc",
"compilerArgs": [

What should I change to get the conversion of number strings to double correct?

AFAIK, c_cpp_properties.json is not controlling the compiler (maybe Platformio uses it to generate Makefile, I do not know). What is your Makefile saying?
Problem found and solved. The platformio teensy configurartion file version 4.17 uses the "cxx_flags" switch "-fsingle-precision-constant", which if perfect for the Teensy3.x, because their Floating Point Unit (FPU) can handle only 'floats'. But the Teensy4.x have a FPU, which can handle 'doubles' but this was missed when then platformio teensy configuration for teens3.x was upgraded to teensy4.x. In the teensy platformio version 5.0 this problem was fixed.

Thanks for all hints, Ad.