www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2001/11/16/09:34:12

Message-ID: <3BF4DAEC.7845DFAB@acm.org>
From: Eric Sosman <esosman AT acm DOT org>
X-Mailer: Mozilla 4.72 [en] (Win95; U)
X-Accept-Language: en
MIME-Version: 1.0
Newsgroups: comp.os.msdos.djgpp
Subject: Re: DBL_EPSILON
References: <imk6vtk0jre49lhjone32d9ekiqg9i3a97 AT 4ax DOT com> <3BF1FDC4 DOT 93E42C1B AT earthlink DOT net> <lsq7vts49kmni80sbraq83ju4dq9rea2ta AT 4ax DOT com>
Lines: 46
Date: Fri, 16 Nov 2001 14:22:34 GMT
NNTP-Posting-Host: 12.91.1.167
X-Complaints-To: abuse AT worldnet DOT att DOT net
X-Trace: bgtnsc06-news.ops.worldnet.att.net 1005920554 12.91.1.167 (Fri, 16 Nov 2001 14:22:34 GMT)
NNTP-Posting-Date: Fri, 16 Nov 2001 14:22:34 GMT
Organization: AT&T Worldnet
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

"J.W. Dare" wrote:
> 
> I'm writing in C++ and I wasn't sure of what value to pass to
> setprecision()in order to obtain a reliable answer.  May I conclude
> then that DBL_DIG is the number of significant digits of accuracy for
> a type double?

    No; you can conclude that DBL_DIG is (approximately) the number
of decimal digits of *precision* for a double.

    ("Precision, accuracy, what's this pedant mumbling about?")

    Precision is the "granularity" with which some quantity is
expressed, while accuracy is the difference between the expressed
quantity and the value actually intended.  For example, if I were
to claim that the value of pi is 3.11111, the claim is expressed
to six digits' precision, but has only two digits' accuracy.

    The fact that you carry out some calculation using numbers of
a certain precision is no guarantee that you obtain a result with
comparable accuracy.  Another trivial exercise in pi-throwing:

	float f_pi = 22.0f / 7.0f;
	double d_pi = 22.0 / 7.0;

The calculation of `d_pi' is carried out with greater precision
than that of `f_pi', but the underlying approximation is no more
accurate.

    My examples are trivial, but the study of error propagation
in computations is intricate and occasionally deep.  The field
is known as "Numerical Analysis," and it'd be worth your while
to peruse an introductory textbook on the topic even if you don't
think of yourself as a "number cruncher."

> As an aside, I'm not yet familiar with precision issues concerning
> floating point numbers.  Can someone point me in the direction of a
> good book or web page that discusses this information?

    Goldberg's "What Every Computer Scientist Should Know About
Floating-Point Arithmetic" is widely available on the Web; use your
favorite search engine.

-- 
Eric Sosman
esosman AT acm DOT org

- Raw text -


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