This is the mail archive of the
cygwin@cygwin.com
mailing list for the Cygwin project.
RE: Strange behavior
- From: Ross Smith <rosss at pharos dot co dot nz>
- To: 'Chuck Allison' <cda at freshsources dot com>, cygwin at cygwin dot com
- Date: Mon, 4 Mar 2002 15:04:43 +1300
- Subject: RE: Strange behavior
> From: Chuck Allison [mailto:cda@freshsources.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/