Neil Schellenberger(deleted)
|
RE: long double bug (6.4.0)
|
Neil Schellenberger(deleted)
11/24/2008 5:10 PM
post17229
|
RE: long double bug (6.4.0)
Interesting! qcc 4.2.4 and (Linux) gcc 4.3.0 both get it right. I'm afraid that I didn't go back and try anything
older.
But now that you've mentioned it, I took a good long look into it. And really wished I hadn't... :-P
On the surface of it, you're right: if the only viable functions present are:
long double std::pow(long double, long double);
double std::pow(double, double);
float std::pow(float, float);
the call would be ambiguous according to the rules of section 13 of ISO/IEC 14882:2003.
The trick is, of course, that those aren't the only viable functions.... There is dark magic involved in this: much
template madness abounds. At the root is the fact that newer compilers and their C++ libraries have begun to
incorporate changes from ISO/IEC DTR 19768 (aka TR1), specifically 8.16.4(4):
Moreover, there shall be additional overloads sufficient to ensure:
1. If any argument corresponding to a double parameter has type long double, then all arguments corresponding
to double parameters are effectively cast to long double.
2. Otherwise, if any argument corresponding to a double parameter has type double or an integer type, then all
arguments corresponding to double parameters are effectively cast to double.
3. Otherwise, all arguments corresponding to double parameters are effectively cast to float.
The specific mechanics of implementing this are thoroughly disgusting and not recommended for human consumption. If you
insist on inflicting them upon yourself, the QNX specifics can be found towards the end of math.h and in xtgmath.h; the
(marginally less horrific) Linux details are in cmath.
Urk.
Regards,
Neil
-----Original Message-----
From: Mario Charest [mailto:community-noreply@qnx.com]
Sent: Mon 11/24/2008 3:31 PM
To: ostech-core_os
Subject: RE: long double bug (6.4.0)
-----Original Message-----
From: Neil Schellenberger [mailto:community-noreply@qnx.com]
Sent: November-24-08 1:47 PM
To: ostech-core_os
Subject: RE: long double bug (6.4.0)
Actually, thanks to that nightmare that is C++ overload resolution, I don't think it is ambiguous; the signature of the
best viable function must be
long double std::pow(long double, long double);
[To make an obscenely long story - a dozen or so pages of standardese - short: double to long double (a promotion) is a
"better implicit conversion sequence" than long double to double (a conversion)....]
I tried to compile it (qcc math.cpp -lm ) and I get:
math.cpp:7: error: call of overloaded `pow(long double, double)' is ambiguous
That with gcc 3.3.5 and 4.2.1é
_______________________________________________
OSTech
http://community.qnx.com/sf/go/post17221
|
|
|