Bug List: (This bug is not in your last search results)   Show last search results      Search page      Enter new bug
Bug#: 11518
Product:  
Component:  
Status: RESOLVED
Resolution: DUPLICATE of bug 323
Assigned To: Not yet assigned to anyone <unassigned@gcc.gnu.org>
Host:
Reported against  
Priority:  
Severity:  
Target Milestone:  
 
 
Target:
Reporter: Gaspar Sinai <gsinai@yudit.org>
Add CC:
CC:
Remove selected CCs
Build:
URL:
Summary:
Keywords:
Known to work:
Known to fail:

Attachment Description Type Created Size Actions
Create a New Attachment (proposed patch, testcase, etc.) View All

Bug 11518 depends on: Show dependency tree
Show dependency graph
Bug 11518 blocks:

Additional Comments:






View Bug Activity   |   Format For Printing   |   Clone This Bug


Description:   Last confirmed: Opened: 2003-07-14 12:36
(b==a && c==a && c!=b) 
Tths equation is somtimes true with redhat built gcc 2.6 on Pentiums.
a: double type
b: function call returning a double
c: method call returning a double

/*!
 * \file double.cpp
 * \brief If a==b and b==c then c==b? Not always. Not everywhere.
 * \author Gaspar Sinai <gsinai@yudit.org>
 * \date   2003-07-13.
 * Results:
 *--------------------------------------------------------------
 * Surprises
 *--------------------------------------------------------------
 * Pentium g++ 2.96:
 * setting: a_double: 0.1
 * setting: get_double(): 0.1
 * setting: a_Double.get(): 0.1
 * comparing: a_double == get_double()
 * comparing: a_double == a_Double.get()
 * comparing: a_Double.get() != get_double()
 *--------------------------------------------------------------
 * Pentium g++ 3.2.1:
 * setting: a_double: 0.1
 * setting: get_double(): 0.1
 * setting: a_Double.get(): 0.1
 * comparing: a_double != get_double()
 * comparing: a_double == a_Double.get()
 * comparing: a_Double.get() != get_double()
 *--------------------------------------------------------------
 * Expected
 *--------------------------------------------------------------
 * Alpha g++ 2.96:
 * setting: a_double: 0.1
 * setting: get_double(): 0.1
 * setting: a_Double.get(): 0.1
 * comparing: a_double == get_double()
 * comparing: a_double == a_Double.get()
 * comparing: a_Double.get() == get_double()
 *--------------------------------------------------------------

 * The interesting function:
 * static double
 * get_double(void)
 * {
 *   int i=1;
 *   // If you change i to 1 it will work everywhere. 
 *   return (double (i) / 10.0);
 * }
 */
#include  <iostream>

static double get_double(void);

class Double
{
public:
 double get(void);
 void set(double d);
protected:
 double m_d;
};

double
Double::get (void)
{
  return m_d;
}

void
Double::set (double d)
{
  m_d = d;
}

static double
get_double(void)
{
  int i=1;
  // If you change i to 1 it will work everywhere. 
  return (double (i) / 10.0);
}

int
main()
{
  double a_double = get_double();
  Double a_Double;
  a_Double.set (get_double());

  std::cout << "setting: a_double: " << a_double << std::endl;
  std::cout << "setting: get_double(): " << get_double() << std::endl;
  std::cout << "setting: a_Double.get(): " << a_Double.get() << std::endl;

  if (a_double == get_double())
  {
    std::cout << "comparing: a_double == get_double()" << std::endl;
  }
  if (a_double != get_double())
  {
    std::cout << "comparing: a_double != get_double()" << std::endl;
  }
  if (a_double == a_Double.get())
  {
    std::cout << "comparing: a_double == a_Double.get()" << std::endl;
  }
  if (a_double != a_Double.get())
  {
    std::cout << "comparing: a_double != a_Double.get()" << std::endl;
  }
  if (a_Double.get() == get_double())
  {
    std::cout << "comparing: a_Double.get() == get_double()" << std::endl;
  }
  if (a_Double.get() != get_double())
  {
    std::cout << "comparing: a_Double.get() != get_double()" << std::endl;
  }
  return (0);
}

------- Comment #1 From Andrew Pinski 2003-07-14 12:45 -------
This is known as the excess precision problem, read the references in bug 323.
Closing as a dup of 323.

*** This bug has been marked as a duplicate of 323 ***

Bug List: (This bug is not in your last search results)   Show last search results      Search page      Enter new bug