Project Home
Project Home
Documents
Documents
Wiki
Wiki
Discussion Forums
Discussions
Project Information
Project Info
Forum Topic - long double bug (6.4.0): (9 Items)
   
long double bug (6.4.0)  
The following simple test gives the incorrect result of "nan":

#include <cmath>
#include <iostream>

int main()
{
	std::cout << std::pow(0.5L, 16.182502746582031) << std::endl;
}

Seemingly irrelevant changes to the code make the error come and go. The simplest way to compile it is with QCC -lm.

Is this the proper place for a non-commercial user to report bugs? I also have a couple of C++ standard library header 
bugs to report.
RE: long double bug (6.4.0)  
How can this code even compile, the code is ambiguous

-----Original Message-----
From: Niklas Angare [mailto:community-noreply@qnx.com] 
Sent: November-22-08 7:39 PM
To: ostech-core_os
Subject: long double bug (6.4.0)

The following simple test gives the incorrect result of "nan":

#include <cmath>
#include <iostream>

int main()
{
	std::cout << std::pow(0.5L, 16.182502746582031) << std::endl;
}

Seemingly irrelevant changes to the code make the error come and go. The simplest way to compile it is with QCC -lm.

Is this the proper place for a non-commercial user to report bugs? I also have a couple of C++ standard library header 
bugs to report.

_______________________________________________
OSTech
http://community.qnx.com/sf/go/post17135

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)....]

And a result of NaN would indeed be incorrect for any reasonable floating point implementation.  

Niklas, can you provide more details?  (Platform type, compile/link command line, etc.)  You can most certainly report 
bugs here and we'll do our best to create Problem Reports (PRs) for them.  Also, if you have a support agreement you can
 of course go through customer support.

Regards,
Neil

P.S.  If you are using gcc 2.95 then it would be wise to upgrade if you can.  The C++ support in 2.95 is a bit ... 
spotty. ;-)

-----Original Message-----
From: Mario Charest [mailto:community-noreply@qnx.com]
Sent: Mon 11/24/2008 8:28 AM
To: ostech-core_os
Subject: RE: long double bug (6.4.0)
 

How can this code even compile, the code is ambiguous

-----Original Message-----
From: Niklas Angare [mailto:community-noreply@qnx.com] 
Sent: November-22-08 7:39 PM
To: ostech-core_os
Subject: long double bug (6.4.0)

The following simple test gives the incorrect result of "nan":

#include <cmath>
#include <iostream>

int main()
{
	std::cout << std::pow(0.5L, 16.182502746582031) << std::endl;
}

Seemingly irrelevant changes to the code make the error come and go. The simplest way to compile it is with QCC -lm.

Is this the proper place for a non-commercial user to report bugs? I also have a couple of C++ standard library header 
bugs to report.

_______________________________________________
OSTech
http://community.qnx.com/sf/go/post17135



_______________________________________________
OSTech
http://community.qnx.com/sf/go/post17158


Re: RE: long double bug (6.4.0)  
Ok!

The platform is QNX 6.4.0 (as the subject line) and the command line was QCC -lm as I said. Just add the filename at the
 end and then run ./a.out.
RE: RE: long double bug (6.4.0)  
Hi Niklas,

Just to confirm, are you running on an x86 platform?  Also you mentioned that some small changes to the simple sample 
code seemed to produce different results.  Could you post those too?

Regards,
Neil

P.S. If you also have some STL bugs, feel free to post those as well.  (Perhaps in a separate thread for each problem if
 you have the time.)

-----Original Message-----
From: Niklas Angare [mailto:community-noreply@qnx.com]
Sent: Mon 11/24/2008 3:19 PM
To: ostech-core_os
Subject: Re: RE: long double bug (6.4.0)
 
Ok!

The platform is QNX 6.4.0 (as the subject line) and the command line was QCC -lm as I said. Just add the filename at the
 end and then run ./a.out.

_______________________________________________
OSTech
http://community.qnx.com/sf/go/post17218


Re: RE: RE: long double bug (6.4.0)  
Ah, sorry. It's x86. I'm not used to operating systems supporting multiple processor architectures.

pow2.cpp:
#include <cmath>
#include <iostream>

int main()
{
 long double exp1 = 16.182502746582031;
 long double exp2 = 16.182502746582031L;
 long double res1 = std::pow(0.5L, exp1);
#if VER>1
 long double res2 = std::pow(0.5L, exp2);
#endif
 std::cout << res1 << std::endl;
#if VER>1
 std::cout << res2 << std::endl;
#endif
 std::cout << "VER="	<< VER << std::endl;
}

Console log:
# QCC -lm -DVER=1 pow2.cpp
# ./a.out
1.34456e-05
VER=1
# QCC -lm -DVER=2 pow2.cpp
# ./a.out
nan
1.34456e-05
VER=2
# QCC -lm -DVER=2 pow2.cpp -o pow2_v2
# ./pow2_v2
0
1.34456e-05
VER=2

Note that res1 is printed as 1.3x with VER=1 and nan with VER=2 even though the code related to res1 is the same. 
Apparently you can get 0 as well...
Re: RE: RE: long double bug (6.4.0)  
Hi Niklas,

I've forwarded this on to our toolchain folks to see what they have to say.

They mostly hang out in the Core Development Tools forum over at

  http://community.qnx.com/sf/discussion/do/listTopics/projects.toolchai/discussion.core_development_tools/

Regards,
Neil
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é
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