cvs.gedasymbols.org/archives/browse.cgi   search  
Mail Archives: djgpp/1998/07/13/17:45:27

From: plipson AT my-dejanews DOT com
Newsgroups: comp.os.msdos.djgpp
Subject: Use of FLT_EPSILON
Date: Mon, 13 Jul 1998 20:27:46 GMT
Organization: Deja News - The Leader in Internet Discussion
Lines: 34
Message-ID: <6odqk1$p23$1@nnrp1.dejanews.com>
References: <3587a411 DOT 12016463 AT news DOT polimi DOT it> <Pine DOT SUN DOT 3 DOT 91 DOT 980617170255 DOT 20468H-100000 AT is>
NNTP-Posting-Host: 207.77.64.13
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

In article <Pine DOT SUN DOT 3 DOT 91 DOT 980617170255 DOT 20468H-100000 AT is>,
  Eli Zaretskii <eliz AT is DOT elta DOT co DOT il> wrote:
>
> the following Golden Rule Of Comparing
> Floating-Point Numbers:
>
>   To check whether two floating-point numbers a and b are equal, use the
>   following paradigm:
>
> 		if (fabs (a - b) > min (fabs(a), fabs(b))*DBL_EPSILON)
> 		  printf ("Not equal\n");
> 		else
> 		  printf ("Equal\n");
>
>   (Use FLT_EPSILON for floats, LDBL_EPSILON for long doubles; all of them
>   are defined on <float.h>.)
>
> In other words, don't EVER compare FP numbers for exact equality, since
> floating-point computations have inherent inaccuracy, unlike integer
> numbers.

  This looks pretty ugly (the multiply and even more the min() ) - isn't
there a better way? And what about comparing an expression to zero?

  I tried several; since FLT_EPSILON is defined in terms of 1 -
   if( fabs(a-b) < FLT_EPSILON....
   if( (1 + fabs(a-b)) < (1+FLT_EPSILON).....
  and a few others.
    Does anyone have an explanation of what & why to do?

Peter

-----== Posted via Deja News, The Leader in Internet Discussion ==-----
http://www.dejanews.com/rg_mkgrp.xp   Create Your Own Free Member Forum

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019