-
-
Notifications
You must be signed in to change notification settings - Fork 7k
AVR: sprintf() not working for floats #3567
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
no never!! e.g.; sprintf(sbuf, "poll: %-5d - heading: %6.2f pitch: %5.2f roll: %5.2\n", dvar, fvar1, fvar2, fvar3); With the Due it works fine, but on the Mega without lib.c float patch this becomes very big rubbish !! |
Due to the way sprintf works, enabling the float support is only possible by adding a linker option, there is not any reasonable way I can think of to enable it from inside a sketch using an include or whatever. There has been some discussion on the list about (s)printf recently, and it was clear that it is not part of the supported Arduino API, so no extensive effort will be made to more easily support it. If you really need float support, you will need to modify the compiler options by modifying platform.txt or boards.txt. Ideally, you could add additional compiler options per sketch to simplify this, but that isn't supported yet (IIRC there is an issue about this already). I'm closing this issue as wontfix. If you have specific ideas about how to fix this, feel free to leave another comment (or submit a pullrequest). |
I would appreciate it you please re-opened this issue! as by copying the lib.c float patch it seems there is a way to fix this issue for AVRs and make sprintf process float formatters by AVRs. So would it be possible to have 2 different sprintf versions, e.g. sprintftiny() just for small AVRs w/o float support If there exist 2 difefrent sprintf versions maybe one could even automate this by
BTW: OT: |
I'm not sure what this patch is. Do you have a link? AFAIK, avr-libc provides two sprintf libraries, both providing a As for the editor - use triple backticks ``` before and after a code block. I have updated your comment to apply this. |
to the lib.c float patch I have made an upload in our forum, please look here if you wish: can you please make this topic "open" again" ? |
Hm, I can download those, but the zip only contains a compiled libc version, without source code or an actual .patch file, so that doesn't really tell me anything. I suspect that this might be a version of avr-libc that has float support enabled by default, removing the need for a custom linker option. I had another look at the linker options required and the printf sources in the hope that there might be some way to automatically including the float-supported printf by referencing a special symbol, but it seems that each version exports exactly the same symbols, so that won't work.
Since I'm still not sure what Arduino should be changing to improve this and it's unlikely that a lot of effort will be invested in printf-related stuff, I'd rather keep it closed until it's clear that something needs changing. One thing I could imagine being changed is to make it easier to supply custom compiler options from a sketch, but that would warrant a separate issue (which I think already exists).
That's a bit of a broad question, please check out the github docs and other stuff written about this in Google. |
yes, the lib contains ALMOST a complete lib.c version. It must be copy-and-pasted into the program folder to replace the original ones. Well, about this sprintf issue: Maybe other readers will have ideas about how to fix or resolve this issue. Thank you! |
for AVRs sprintf() is not working for floats (on Due it works though).
To make it work, a lib.c float patch has to be issued.
this is actually unreasonable, e.g. for the Mega.
Please enable this feature by #include or #pragma config or anything.
On very small boards one may refrain from #including it to save memory nevertheless.
The text was updated successfully, but these errors were encountered: