delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2002/03/03/21:06:10

Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sources.redhat.com/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sources.redhat.com/ml/#faqs>
Sender: cygwin-owner AT cygwin DOT com
Delivered-To: mailing list cygwin AT cygwin DOT com
Message-ID: <79218202D4B9D4118A290002A508E13B79C373@PNZEXCHANGE>
From: Ross Smith <rosss AT pharos DOT co DOT nz>
To: "'Chuck Allison'" <cda AT freshsources DOT com>, cygwin AT cygwin DOT com
Subject: RE: Strange behavior
Date: Mon, 4 Mar 2002 15:04:43 +1300
MIME-Version: 1.0
X-Mailer: Internet Mail Service (5.5.2653.19)

> From: Chuck Allison [mailto:cda AT freshsources DOT com]
> 
> I have a simple Rational number class and have discovered  
> weird behavior
> with Cygwin's g++. If you look at the very short main program in file
> rtest2.cpp, you will see by the output that g++ get's the 
> wrong answer for
> 
> r1 / r2 == Rational(2,3); // should be true
> 
> even though it prints as 2/3! Borland and Microsoft get it 
> right. Any ideas?
> All code atached.

[relevant bit of code]

inline bool operator==(const Rational& r1, const Rational& r2)
{
   return r1.toDouble() == r2.toDouble();
}

This is nothing to do with Cygwin, or g++ for that matter. You're
comparing floating point numbers. Of course it's not reliable! If
other compilers happened to give you an exact equality on that
particular combination of arguments, it was pure luck.

--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Bug reporting:         http://cygwin.com/bugs.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019