Re: Division in C++

"Marcin 'Qrczak' Kowalczyk" <qrczak@knm.org.pl>
12 Jul 2005 05:12:04 -0400

          From comp.compilers

Related articles
Division in C++ garms@gmx.de (Onno Garms) (2005-07-11)
Re: Division in C++ antounk@comcast.net (Antoun Kanawati) (2005-07-12)
Re: Division in C++ qrczak@knm.org.pl (Marcin 'Qrczak' Kowalczyk) (2005-07-12)
Re: Division in C++ tmk@netvision.net.il (Michael Tiomkin) (2005-07-12)
Re: Division in C++ henry@spsystems.net (2005-07-12)
Re: Division in C++ fw@deneb.enyo.de (Florian Weimer) (2005-07-12)
Re: Division in C++ gdr@integrable-solutions.net (Gabriel Dos Reis) (2005-07-12)
Re: Division in C++ qrczak@knm.org.pl (Marcin 'Qrczak' Kowalczyk) (2005-07-12)
Re: Division in C++ garms@gmx.de (Onno Garms) (2005-07-17)
[1 later articles]
| List of all articles for this month |

From: "Marcin 'Qrczak' Kowalczyk" <qrczak@knm.org.pl>
Newsgroups: comp.compilers,gnu.g++.help
Date: 12 Jul 2005 05:12:04 -0400
Organization: Klub Nieszkodliwych =?iso-8859-2?q?Manjak=F3w?=
References: 05-07-046
Keywords: C++, arithmetic
Posted-Date: 12 Jul 2005 05:12:04 EDT

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/



Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.