public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/55787] New: Comparisons of double values don't work correctly
@ 2012-12-22 15:24 tasin at hm dot edu
2012-12-22 17:30 ` [Bug c++/55787] " daniel.kruegler at googlemail dot com
` (4 more replies)
0 siblings, 5 replies; 6+ messages in thread
From: tasin at hm dot edu @ 2012-12-22 15:24 UTC (permalink / raw)
To: gcc-bugs
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;
}
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug c++/55787] Comparisons of double values don't work correctly
2012-12-22 15:24 [Bug c++/55787] New: Comparisons of double values don't work correctly tasin at hm dot edu
@ 2012-12-22 17:30 ` daniel.kruegler at googlemail dot com
2012-12-22 18:29 ` schwab@linux-m68k.org
` (3 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: daniel.kruegler at googlemail dot com @ 2012-12-22 17:30 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=55787
Daniel Krügler <daniel.kruegler at googlemail dot com> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |daniel.kruegler at
| |googlemail dot com
--- Comment #1 from Daniel Krügler <daniel.kruegler at googlemail dot com> 2012-12-22 17:30:37 UTC ---
Using gcc 4.8.0 20121209 (experimental) (also mingw, but 64-bit on Windows 7)
returns "false" for me.
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug c++/55787] Comparisons of double values don't work correctly
2012-12-22 15:24 [Bug c++/55787] New: Comparisons of double values don't work correctly tasin at hm dot edu
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
` (2 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: schwab@linux-m68k.org @ 2012-12-22 18:29 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=55787
--- Comment #2 from Andreas Schwab <schwab@linux-m68k.org> 2012-12-22 18:28:49 UTC ---
Most likely a dup of bug 323.
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug c++/55787] Comparisons of double values don't work correctly
2012-12-22 15:24 [Bug c++/55787] New: Comparisons of double values don't work correctly tasin at hm dot edu
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
4 siblings, 0 replies; 6+ messages in thread
From: redi at gcc dot gnu.org @ 2012-12-22 20:11 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=55787
Jonathan Wakely <redi at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Severity|critical |normal
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug c++/55787] Comparisons of double values don't work correctly
2012-12-22 15:24 [Bug c++/55787] New: Comparisons of double values don't work correctly tasin at hm dot edu
` (2 preceding siblings ...)
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
4 siblings, 0 replies; 6+ messages in thread
From: rguenth at gcc dot gnu.org @ 2012-12-31 16:12 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=55787
Richard Biener <rguenth at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |RESOLVED
Resolution| |DUPLICATE
--- Comment #3 from Richard Biener <rguenth at gcc dot gnu.org> 2012-12-31 16:12:05 UTC ---
Use -fexcess-precision=standard
*** This bug has been marked as a duplicate of bug 323 ***
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug c++/55787] Comparisons of double values don't work correctly
2012-12-22 15:24 [Bug c++/55787] New: Comparisons of double values don't work correctly tasin at hm dot edu
` (3 preceding siblings ...)
2012-12-31 16:12 ` rguenth at gcc dot gnu.org
@ 2012-12-31 16:50 ` redi at gcc dot gnu.org
4 siblings, 0 replies; 6+ messages in thread
From: redi at gcc dot gnu.org @ 2012-12-31 16:50 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=55787
--- Comment #4 from Jonathan Wakely <redi at gcc dot gnu.org> 2012-12-31 16:50:21 UTC ---
If only ...
cc1plus: sorry, unimplemented: -fexcess-precision=standard for C++
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2012-12-31 16:50 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-12-22 15:24 [Bug c++/55787] New: Comparisons of double values don't work correctly tasin at hm dot edu
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
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).