Linker | printf | accuracy problems

Hello RIOT Team,

1 Question:

I try to calculate some floating point digits on the SAMR21-xpro Board. When I print the floating point digit it shows me nothing.

My Code:

Hi Oliver,

See my answer about printf below. I'm not enough expert with timer accuracy but there are known issues with xtimer, maybe have a look at related issues/PRs on github ?

1 Question:

I try to calculate some floating point digits on the SAMR21-xpro Board. When I print the floating point digit it shows me nothing.

My Code:

uint32_t time_diff = 554;

double distance = (33./2000.) * time_diff; printf("distance = %f cm\n",distance);

Output:

2019-07-31 14:36:58,631 - INFO # distance = cm

Stack Overflow [1] tells me that floating point are disabled by default on arm-gcc. Whats the trick ?? What should I add to the Makefile ?

Just add USEMODULE += printf_float to your application Makefile. Note that this will noticeably increase the generated firmware size.

Alex

Can somebody explain, why it increases the size so much? I have a rough idea, but would be nice to get an explanation :slight_smile:

Hi,

Can somebody explain, why it increases the size so much? I have a rough idea, but would be nice to get an explanation :slight_smile:

printf_float also enables double printf support, and because they are always referenced by printf through the format specifier handler, that cannot be garbage collected.

Double arithmetic is mostly done in software, and in a standard compliant way (IEEE754?), so that's expensive.

Here's what's added by just adding USEMODULE += printf_float to hello_world:

Kaspar