Accelerating the pace of engineering and science

# Documentation Center

• Trial Software

# eps

Floating-point relative accuracy

eps
d = eps(X)
eps('double')
eps('single')

## Description

eps returns the distance from 1.0 to the next largest double-precision number, that is eps = 2^(-52).

d = eps(X) is the positive distance from abs(X) to the next larger in magnitude floating point number of the same precision as X. X may be either double precision or single precision. For all X,

`eps(X) = eps(-X) = eps(abs(X))`

eps('double') is the same as eps or eps(1.0).

eps('single') is the same as eps(single(1.0)) or single(2^-23).

Except for numbers whose absolute value is smaller than realmin , if 2^E <= abs(X) < 2^(E+1), then

```eps(X) = 2^(E-23) if isa(X,'single')
eps(X) = 2^(E-52) if isa(X,'double')```

For all X of class double such that abs(X) <= realmin, eps(X) = 2^(-1074). Similarly, for all X of class single such that abs(X) <= realmin('single'), eps(X) = 2^(-149).

Replace expressions of the form:

`if Y < eps * ABS(X)`

with

`if Y < eps(X)`

## Examples

```double precision
eps(1/2) = 2^(-53)
eps(1) = 2^(-52)
eps(2) = 2^(-51)
eps(realmax) = 2^971
eps(0) = 2^(-1074)

if(abs(x)) <= realmin, eps(x) = 2^(-1074)
eps(realmin/2) = 2^(-1074)
eps(realmin/16) = 2^(-1074)
eps(Inf) = NaN
eps(NaN) = NaN

single precision
eps(single(1/2)) = 2^(-24)
eps(single(1)) = 2^(-23)
eps(single(2)) = 2^(-22)
eps(realmax('single')) = 2^104
eps(single(0)) = 2^(-149)
eps(realmin('single')/2) = 2^(-149)
eps(realmin('single')/16) = 2^(-149)
if(abs(x)) <= realmin('single'), eps(x) = 2^(-149)
eps(single(Inf)) = single(NaN)
eps(single(NaN)) = single(NaN)```