public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "tasin at hm dot edu" <gcc-bugzilla@gcc.gnu.org> To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/55787] New: Comparisons of double values don't work correctly Date: Sat, 22 Dec 2012 15:24:00 -0000 [thread overview] Message-ID: <bug-55787-4@http.gcc.gnu.org/bugzilla/> (raw) http://gcc.gnu.org/bugzilla/show_bug.cgi?id=55787 Bug #: 55787 Summary: Comparisons of double values don't work correctly Classification: Unclassified Product: gcc Version: 4.7.2 Status: UNCONFIRMED Severity: critical Priority: P3 Component: c++ AssignedTo: unassigned@gcc.gnu.org ReportedBy: tasin@hm.edu Created attachment 29027 --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=29027 example code (as .ii) A simple comparison shows that floating point operations with the c++-type double doesn't set the floating status flag correctly. Changing the type of the members of the class Load to float or long double makes the application work correctly. In the attached example the free function bool operator<(const Load &, const Load &); doesn't work correctly. The example returns the output: Compare: true instead of Compare: false This example was compiled in different configurations and on different machines with the same wrong result: System configuration 1: --- Intel(R) Core(TM)2 CPU 6420 @ 2.13GHz 3 GB RAM (pae) Windows XP Professional Version 2002 SP3 32 bit arch --- Es werden eingebaute Spezifikationen verwendet. COLLECT_GCC=g++ COLLECT_LTO_WRAPPER=c:/mingw/bin/../libexec/gcc/mingw32/4.7.2/lto-wrapper.exe Ziel: mingw32 Konfiguriert mit: ../gcc-4.7.2/configure --enable-languages=c,c++,ada,fortran,objc,obj-c++ --disable-sjlj-exceptions --with-dwarf2 --enable-shared --enable-libgomp --disable-win32-registry --enable-libstdcxx-debug --disable-build-poststage1 -with-cxx --enable-version-specific-runtime-libs --build=mingw32 --prefix=/mingw Thread-Modell: win32 gcc-Version 4.7.2 (GCC) --- The build process call was: g++ -v -save-temps -Wall -pedantic -Wextra -o derror.exe src\derror.cpp --- derror.cpp --- // test routine to show the double error #include <iostream> #include <stdexcept> using namespace std; // class definition class Load { double m_dPowerOut, m_dEfficiency; public: Load(double powerOut, double eff=1) : m_dPowerOut(powerOut), m_dEfficiency(eff) { }; virtual double consumption() const; virtual ~Load() { } }; bool operator<(const Load &a, const Load &b); // class method definition double Load::consumption(void) const { if (m_dEfficiency==0.0) throw logic_error("Efficiency must not be 0"); return m_dPowerOut/m_dEfficiency; } /// free function // ... doesn't work correctly bool operator<(const Load &a, const Load &b) { return a.consumption() < b.consumption(); } /* // ... seems to work correctly, but the float-status-flag IMHO // still isn't correct bool operator<(const Load &a, const Load &b) { double bcon=b.consumption(); return a.consumption() < bcon; } */ int main() { try { Load pump(53.0, 0.43); bool cmp=(pump < pump); // should be false !!! cout << "Compare: " << (cmp ? "true" : "false") << endl; } catch (const exception &ex) { cerr << "Exception: " << ex.what() << endl; } return 0; }
next reply other threads:[~2012-12-22 15:24 UTC|newest] Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top 2012-12-22 15:24 tasin at hm dot edu [this message] 2012-12-22 17:30 ` [Bug c++/55787] " daniel.kruegler at googlemail dot com 2012-12-22 18:29 ` schwab@linux-m68k.org 2012-12-22 20:11 ` redi at gcc dot gnu.org 2012-12-31 16:12 ` rguenth at gcc dot gnu.org 2012-12-31 16:50 ` redi at gcc dot gnu.org
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=bug-55787-4@http.gcc.gnu.org/bugzilla/ \ --to=gcc-bugzilla@gcc.gnu.org \ --cc=gcc-bugs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).