eps

Floating-point spacing: the distance from a number to the next larger representable one.

Category: Language Fundamentals > Data Types

Syntax

e = eps

Returns the spacing at 1, 2^-52.

e = eps(X)

Returns the spacing at each element of X.

e = eps('single')

Returns the spacing at 1 for single precision.

Description

Floating-point numbers are not evenly spaced: the gap between neighbors grows with the magnitude. eps(x) is the gap between abs(x) and the next larger number of the same class. Values smaller than eps(x)/2 added to x are lost to rounding.

The spacing doubles each time the number crosses a power of two. For 0 the result is the smallest positive denormalized number.

Input arguments

X
Numeric array, or the class name 'double' or 'single'.

Output arguments

e
Spacing values, the same size as X, in the class of X.

Example

Spacing at different magnitudes

eps
eps(1000)
eps(single(1))
1 + eps/2 == 1
Output
ans = 2.2204e-16
ans = 1.1369e-13
ans = 2.2204e-16
ans = logical
   1

See also

realmin realmax flintmax single double