octave-maintainers
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: eps function and numerical accuracy


From: Dr. Alexander Klein
Subject: Re: eps function and numerical accuracy
Date: Tue, 9 Jul 2013 13:35:22 +0200

Am 09.07.2013 um 00:31 schrieb Daniel J Sebald:

>     Return a scalar, matrix or N-dimensional array whose elements are
>     all eps, the machine precision.  More precisely, `eps' is the
>     relative spacing between any two adjacent numbers in the machine's
>     floating point system.  This number is obviously system dependent.
>     On machines that support IEEE floating point arithmetic, `eps' is
>     approximately 2.2204e-16 for double precision and 1.1921e-07 for
>     single precision.
> 
> There is a more to the documentation, but it is this first part that sort of 
> imparts the meaning.  I suppose if one thinks about it long enough, "relative 
> spacing between any two adjacent numbers" is kind of correct.  But what it 
> doesn't impart clearly is the fact this reflects the nature of the mantissa.  
> The relative part sort of pertains to the exponent.  In the latter half of 
> the above paragraph, it should probably state

Daniel,

I'm really not sure what the standards say, but I seem to remember that EPS in 
C is defined as the smallest positive number such that 1+EPS != 1, or rather 
(1+EPS)-1==EPS.

As a first approximation, this seems to be the case in Octave, too:

> eps(1)
ans =  2.22044604925031e-16
> eps(2)
ans =  4.44089209850063e-16

> 1+eps(1)==1
ans = 0
> 2+eps(1)==2
ans =  1

Then again, there are positive numbers smaller than eps giving the same result:

> eps(1)/(1+eps(1))<eps(1)
ans =  1
> 1+eps(1)/(1+eps(1))==1
ans = 0
> 1+eps(1)/(1+eps(1))-1==eps(1)
ans =  1

There's obviously more to it than meets the eye, and I think the exact 
behaviour in any given case - as opposed to what the documentation of eps() may 
suggest as valid implications - will depend on the FPU (its registers may be 
wider than double), and at least the flags ffloat-store, 
fexcess-precision=style, funsafe-math-optimizations, freciprocal-math, and a 
few others when compiling with gcc.

Best,

        Alex

-- 
Dr. Alexander Klein, Diplom-Mathematiker
TransMIT-Projektbereich für Mathematische Analysen und Feld-Simulationen
Kerkrader Straße 3
D-35394 Gießen

http://www.transmit.de/zentren/tz.cfm?N=165



reply via email to

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