help-gplusplus
[Top][All Lists]
Advanced

[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/



reply via email to

[Prev in Thread] Current Thread [Next in Thread]