Arduino printf and sprintf

I see that the Artemis Arduino implementation supports printf(), for which I am very, very grateful. However, sprintf/snprint seems broken:

  float f = 123.4567;
  int32_t count = Serial.printf("Yay printf: %.1f\n", f);
  Serial.printf("printf() count: %ld\n", count);

  char buffer[16];
  count = snprintf(buffer, sizeof(buffer), "Boo snprintf: %.1f", f);
  Serial.printf("String <%s> is %ld chars long\n", buffer, count);

The output is as follows:

Yay printf: 123.5
printf() count: 18
String <Boo snprintf: > is 78479 chars long

The printf print of a float is rounded to the 1 digit of precision that I asked for. In contrast, the snprintf call processes the string portion of the format string properly but totally bails on dealing with the float conversion. The character count returned by printf is correct, but the character count returned by sprintf when a float is involved is complete garbage.

Is this a basic Arduino issue or is this an issue with the Artemis implementation of Arduino? Given that Artemis supports native floating point, it would be really nice to make use of it everywhere.

This brings up big issue nightmares for me. There have been issues in the past regarding various compiler (GCC) versions not handling floating point well. I don’t fully understand yet - it could very well be some dumb bit somewhere that causes the hardware floating point support to get munged. I don’t have a total solution right now but I will open an issue on GitHub so we can remember to get back to it.

https://github.com/sparkfun/Arduino_Apollo3/issues/239