I have following program:
#include <stdio.h>
int main(int args, char *argv[]) {
printf("%f\n", 0.99999);
printf("%e\n", 0.99999);
}
The result is:
0.009990
9.999900e-001
Why is the first number wrong? I use Windows XP, compiler "Logiciels Informatique lcc-win32 version 3.8. Compilation date: Nov 30 2012 19:38:03".
You can check that printf float is enabled for your build configuration by right clicking on your project in the [Project Explorer] window, selecting [C/C++ Build]> [Settings], then under [GNU ARM C Linker]> [General], check the [Printf float] checkbox beneath the [C Library] selection box:
Add "-u _printf_float" as a linker option to get printf support for %f. Do this by: Right-click the root of the project in the project explorer > [Properties] Navigate to [ C/C++ Build] > [Settings] > [Tool Settings] > [Gnu ARM C Linker] > [Miscellaneous] Add "-u _printf_float" in the [ Linker flags] line.
Add "-u _printf_float" in the [ Linker flags] line. Please note that there is also a method to enable floating point printf () with the newlib-nano library using the Simplicity Studio Preferences GUI.
Go to Miscellaneous in Toolchain -> ARM/GNU Linker Add --specs=nano.specs -lc -u _printf_float in the linker flags The software floating point support for printf library was not available with the earlier versions of Atmel ARM GNU Toolchain.
That program is correct, and its output should be:
0.999990
9.999900e-01
or something very similar to that.
(You don't use args
or argv
, and the usual name for the first parameter of main
is argc
rather than args
, but neither of those is a problem that should affect your program's behavior.)
It looks like you've found a bug in your implementation, probably in the runtime library rather than in the compiler itself. My brief Google searches haven't turned up a reference to this particular bug (in fact, the top hit was this question).
I suggest contacting the maintainer of lcc-win; contact information is on the web site. A short description and a link to this question should provide enough information, at least to start.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With