Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

lcc printf floating point

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".

like image 727
user2712052 Avatar asked Aug 23 '13 18:08

user2712052


People also ask

How do I enable printf float in C++?

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:

How to get printf support for %F in C++?

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.

How do I enable printf() with the Newlib-nano library?

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.

How to enable floating point printf in Atmel ARM GNU toolchain?

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.


1 Answers

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.

like image 192
Keith Thompson Avatar answered Oct 06 '22 12:10

Keith Thompson