Re: Division in C++

Onno Garms <garms@gmx.de>
17 Jul 2005 13:53:37 -0400

          From comp.compilers

Related articles
[2 earlier articles]
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)
Re: Division in C++ poenitz@htwm.de (Andre Poenitz) (2005-08-10)
| List of all articles for this month |
From: Onno Garms <garms@gmx.de>
Newsgroups: comp.compilers,gnu.g++.help
Date: 17 Jul 2005 13:53:37 -0400
Organization: Compilers Central
References: 05-07-046 05-07-055
Keywords: C, arithmetic, comment
Posted-Date: 17 Jul 2005 13:53:37 EDT

On 12 Jul 2005 05:14:04 -0400, "Michael Tiomkin"
<tmk@netvision.net.il> wrote:




> There is an old rule: never assume or check equality of two floating
>point numbers.


I know about that rule, but I think it's a bad one.


In our company's code, numerical problems are unavoidable and occur
from time to time. Some colleagues introduce tolerances whereever
doubles are compared. Eventually they have numerical problems in spite
of the tolerance, modify the tollerance to fix it - and get another
numerical problem some time later.


My opinion is that it is better to introduce tolrances only in cases
where it is absolutely unavoidable. The example discussed here is not
among these.


Keep rounding errors in the mind (e.g. do not write if (a<=b*c) break;
but do not introduce numerical problems by using tolerances in cases
where there are no initial numerical problems.


The solution with long double works fine. The original code has been
working fine for years on other operating systems.


Thank you to everybody who posted a reply.


Greetings,
Onno
[I agree. I know there's a meme of "all floating results are
wrong" but it's not true. -John]


Post a followup to this message

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