[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Division in C++
From: |
Marcin 'Qrczak' Kowalczyk |
Subject: |
Re: Division in C++ |
Date: |
12 Jul 2005 05:12:04 -0400 |
Onno Garms <garms@gmx.de> writes:
> while (1)
> {
> c = a/b;
> if (a/b<=c) break;
> }
> }
>
> Can anybody explain why this hangs?
C and C++ allow a compiler to compute floating point expressions with
greater precision than apparent in the type, unless the value is
stored in a variable or explicitly cast.
> - if (static_cast<double>(a/b)<=c)
> endless loop
This looks like a bug in the compiler, a cast should cut off excess
precision.
gcc has an option to turn this off: -ffloat-store
--
__("< Marcin Kowalczyk
\__/ qrczak@knm.org.pl
^^ http://qrnik.knm.org.pl/~qrczak/
- Division in C++, Onno Garms, 2005/07/11
- Re: Division in C++, Robert Heller, 2005/07/11
- Re: Division in C++, Antoun Kanawati, 2005/07/12
- Re: Division in C++,
Marcin 'Qrczak' Kowalczyk <=
- Re: Division in C++, Michael Tiomkin, 2005/07/12
- Re: Division in C++, Florian Weimer, 2005/07/12
- Re: Division in C++, Henry Spencer, 2005/07/12