(e-mail address removed) wrote:
Now that you are mentioning it, I think that long double actually works
with cout, but it is broken with printf("%Lf", ld); under MINGW, where
ld is long double, and the rest of C95 functions.
Yes, at least GCC 3.4.2 printf treats %Lf as a regular double, but
leaves "long double" as "long double" when passed through '...' (what
the C++ standard says about long doubles through '...', I don't know
-- but from what I can tell they should not be demoted to double, and
GCC is correct there, at least). So the following:
#include <cstdio>
using std:

rintf;
int main (int, char **) {
double d = 1.0;
long double dd = 1.0L;
printf("%f %Lf ", d, d);
printf("%f %Lf ", dd, dd);
printf("%f %Lf ", (double)dd, (double)dd);
return 0;
}
Produces "1.0 1.0 0.0 0.0 1.0 1.0" with MinGW GCC 3.4.2.
Produces expectedly garbage results on Linux GCC 4.1.2 (since %Lf
works).
Produces "1.0 1.0 0.0 0.0 1.0 1.0" with BCC32 5.93
Produces "1.0 1.0 1.0 1.0 1.0 1.0" with MS CL 12.00 (VS6, since
they're all just "double")
Produces "1.0 1.0 1.0 1.0 1.0 1.0" with MS CL 14.00 (VS2005, same
deal).
So you are just talking about the *printing* of long doubles with
printf? That shouldn't prevent a student from using it. That just
prevents them from using printf to print it on some compilers.
Did you look at the link I sent you? Perhaps the Intel compiler printf
works.
However, if you are going to teach about long doubles, why do you not
want to tell your students about the actual situation? It's very
simple to explain (you could just show them this thread, for example),
and better than having them encounter a broken compiler or something
some day and it catches them by surprise. It's far more practical to
teach a student about a situation they may actually encounter, rather
than teaching theory and letting reality confuse them later. Also,
would you prefer "this doesn't work and Mr. Vranos said it would in my
course last year... what was that guy talking about?", or "Mr. Vranos
told me about this, he definitely knows what's up".
You could always eliminate the problem entirely by just not talking
about long doubles. It really shouldn't be a major issue. Again, I
think that you are concentrating too much on a language quirk that,
while interesting to talk about on a newsgroup, is very minor in
comparison to other aspects of C++ that you would be teaching.