simp1eton's blog

By simp1eton, 10 years ago,
Hi all,

I have some problems with outputting long double.

Here is my code for Yandex Round 1 Problem C Petya and Tree:

http://pastebin.com/sHKuXg15

I submitted this code but got WA for testcase 1, even though it worked on my com. In the end, I realised that I cannot printf long doubles (something similar to printf long long int?), so I changed to cout. However, in that case it seems that I started to output integers :(. All my decimals places got cut off. Can someone help me?

• 0

 10 years ago, # | ← Rev. 2 →   0 I think there is no real need in accuracy, so you may cast your long double to a double.        printf("%.9lf\n",double(AVG[A[P]]));Probably there is no way to output long doubles.UPD:#include #include using namespace std;int main(){   long double d = 0.12345678910;   cout << fixed;   cout << setprecision(12) << d;   return 0;}
•  3 months ago, # ^ |   0 Thank you very much @daftcoder
 10 years ago, # |   -8 As far as I know, in C++ long double have the same precision as double.
•  10 years ago, # ^ |   +3 In MS compiler - yes, but not in GCC.
•  10 years ago, # ^ |   +9 I don't understand why I'm having -2 for my last message, so I'm going to prove that long double exists for some angry trolls and haters.Run this code here with GNU and with MS compiler and see the difference.GNU:Comparing d & ld: 0Comparing d & d:  10.00000000000000001851275209518998800000000000000000MS:Comparing d & ld: 1Comparing d & d:  10.00000000000000000000000000000000000000000000000000
 10 years ago, # |   0 long double x;......printf("%Lf", x);
•  10 years ago, # ^ |   0 Did you try to run that on gcc compiler?#include int main(){   long double d = 1;   printf("%Lf",d);   return 0;}It outputs0.000000MS compiler outputs 1.0... just because there is no difference between double and long double.
•  10 years ago, # ^ |   +8 What GCC do you use???Please, read "man 3 printf":"L - A following a, A, e, E, f, F, g, or G conversion corresponds to a long double argument. (C99 allows %LF, but SUSv2 does not.)"So...% cat >test.cpp <int main(){ long double d = 1; printf("%Lf",d); return 0;} EOF % gcc test.cpp && ./a.out1.000000
•  10 years ago, # ^ |   -8 And what does your compiler outputs for that code?I run that in a custom test on codeforces.
•  10 years ago, # ^ |   0 Comparing d & ld: 0 Comparing d & d: 1 0.00000000000000001851275209518998821067725657485425  Codeforces use gcc throw *ss, so... :)
•  10 years ago, # ^ |   0 However, long double x ;....cout << x;works pretty fine
•  10 years ago, # ^ | ← Rev. 2 →   +1 #include #include using namespace std;int main(){   long double d = 0.12345678910;   cout << fixed;   cout << setprecision(12) << d;   return 0;}=====0.123456789100YARLY. :-)
•  10 years ago, # ^ |   0 Probably, we are facing some issues with MinGW compiler.
 10 years ago, # |   0 You may use specifier Lg for long double:long double x;...printf("%Lg",x);with GNU C++
•  10 years ago, # ^ |   0 Not working on MinGW
 10 years ago, # |   0 Thanks everyone!May I know what is the difference between a MS compiler and GNU compiler?