1

I ran a program like this:

#include <stdio.h>
int main(void)
{
float aboat = 32000.0;
double abet = 2.14e9;
long double dip =5.32e-5;

printf("%f can be written %e\n",aboat,aboat);
printf("And it's %a in hexadecimal, powers of 2 notation\n",aboat);
printf("%f can be written %e\n",abet, abet);
printf("%Lf can be written %Le\n",dip,dip);
                      \\ this statement can not print rightly 
return 0;
}

but it print like this :

32000.000000 can be written 3.200000e+004
And it's 0x1.f40000p+14 in hexadecimal, powers of 2 notation
2140000000.000000 can be written 2.140000e+009
-1950228512509697500000000000000000000000000000000000000000000000000000000000
000000000000000000000000000000000000000000000000000000000000000000000000000.0
00000 can be written 272.500183

as you can see , this result must be incorrect. but I can not find error, so is it a bug attribute to IDE ? I use JetBrains CLion 2017.3.4.

thanks for remind.this is my CMakeList.txt:

cmake_minimum_required(VERSION 3.9)
project(untitled1 C)

set(CMAKE_C_STANDARD 11)

add_executable(untitled1 main.c)

And the gcc version is 6.3.0

Some programmer dude
  • 400,186
  • 35
  • 402
  • 621
zan
  • 51
  • 5
  • 2
    No, the IDE is irrelevant since it is not the IDE which compiles and executes the program. The problem, if there is any, is with the *compiler*. So please tell us which compiler you are using, and which flags you have specified for it (in short, please edit your question to include the `CMakeLists.txt` file as well, and the output of e.g. `gcc --version` if you use GCC). – Some programmer dude Mar 14 '18 at 12:45
  • 3
    Is this on Windows with MinGW gcc? I have this vague memory that there was some problem using `long double` on MinGW because it uses Microsoft libraries. – user694733 Mar 14 '18 at 13:12
  • Yes, but how can I solve this problem? thanks – zan Mar 14 '18 at 13:28
  • Possible duplicate of [Conversion specifier of long double in C](https://stackoverflow.com/questions/1764350/conversion-specifier-of-long-double-in-c) – Andrew Henle Mar 14 '18 at 14:22
  • The last line looks fine to me, and it prints `0.000053 can be written 5.320000e-05` under my compiler and C library. I conclude there's something wrong with yours. – Steve Summit Mar 14 '18 at 14:55
  • That's a problem with mingw. – J...S Mar 15 '18 at 17:52

0 Answers0