From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 107079,c7637cfdf68e766 X-Google-Attributes: gid107079,public X-Google-Thread: f43e6,c7637cfdf68e766 X-Google-Attributes: gidf43e6,public X-Google-Thread: 103376,c7637cfdf68e766 X-Google-Attributes: gid103376,public X-Google-Thread: 109d8a,c7637cfdf68e766 X-Google-Attributes: gid109d8a,public X-Google-Thread: f8362,c7637cfdf68e766 X-Google-Attributes: gidf8362,public From: Daniel Villeneuve Subject: Re: floating point comparison Date: 1997/08/08 Message-ID: #1/1 X-Deja-AN: 262863278 Distribution: world Sender: danielv@halley.crt.umontreal.ca References: <33E61497.33E2@pseserv3.fw.hac.com> <5sar4r$t7m$1@cnn.nas.nasa.gov> <5sbb90$qsc@redtail.cruzio.com> Organization: Centre de Recherche sur les Transports/Groupe d'Etude et de Recherche en Analyse des Decisions Newsgroups: comp.lang.ada,sci.math.num-analysis,comp.software-eng,comp.theory,sci.math Date: 1997-08-08T00:00:00+00:00 List-Id: Gerhard Heinzel writes: > [snip] > Second, if you want to compare two numbers that come from some algorithm > (i.e. is an eigenvalue zero? is a pivot zero? is a correlation coefficient > unity?) In these cases one must NEVER test for exact equality, but always > take into account rounding errors and devise some test such as > > (1) fabs(x-y) > or (2) fabs((x-y)/y) > or (3) something similar, depending on the situation. [ numbers mine] Ok for not testing true equality, but the two cases above are quite different. One of the problems I'm faced is to verify that a point x in R^n is on one side of an hyperplane, i.e. sum_i(a_i*x_i) >= b_i. Should I: a1) compute the sum in x, setting y to b_i and using absolute test (1), a2) same as a1), but using relative test (2), b1) try to avoid numerical cancellation by summing negative terms and positive terms separately, setting x to the positive sum and y to the negative of the negative sum, than using absolute test (1), b2) same as b1), but using relative test (2), Of course, each of the above computed sums is assumed to be computed with the right algorithm, depending on the precision needed (e.g., using Kahan's formula (*) if appropriate). Daniel (*) from David Goldberg's article "What Every Computer Scientist Should Know About Floating-Point Arithmetic"