Main Content

eps

Floating-point relative accuracy

Description

example

d = epsreturns the distance from1.0to the next larger double-precision number, that is, 2-52.

example

d = eps(x), wherexhas data typesingleordouble, returns the positive distance fromabs(x)to the next larger floating-point number of the same precision asx. Ifxhas typeduration, theneps(x)returns the next largerdurationvalue. The commandeps(1.0)is equivalent toeps.

example

d = eps(datatype)returnsepsaccording to the data type specified bydatatype, which can be either"double"or"single". The syntaxeps("double")(default) is equivalent toeps, andeps("single")is equivalent toeps(single(1.0)).

example

d = eps("like",p)returns the positive distance from1.0to the next larger floating-point number of the same precision as the floating-point variablep, with the same data type, sparsity, and complexity (real or complex) asp.

Examples

collapse all

Return the distance from1.0to the next larger double-precision number.

d = eps
d = 2.2204e-16

epsis equivalent toeps(1.0)andeps("double").

Computelog2(eps).

d = log2(eps)
d = -52

In base2,epsis equal to2^-52.

Return the distance from10.0to the next larger double-precision number.

d = eps(10.0)
d = 1.7764e-15

Return the distance from1.0to the next larger single-precision number.

d = eps("single")
d =single1.1921e-07

eps("single")is equivalent toeps(single(1.0)).

Computelog2(eps("single")).

d = log2(eps("single"))
d =single-23

In base2, single-precisionepsis equal to2^-23.

Return the distance from the single-precision representation of 10.0 to the next larger single-precision number.

d = eps(single(10.0))
d =single9.5367e-07

Return the distance from1.0to the next larger floating-point number with the same data type and complexity as an existing array.

First, create a complex vector ofsingledata type.

p = single([0.12+2i -0.5i 3]);

Return the distance from1.0to the next larger floating-point number as a scalar that is complex likep.

d = eps("like",p)
d =single1.1921e-07 +0.0000e+00i

Create a 10-by-10 sparse matrix.

p = sparse(10,10,pi);

Return the distance from1.0to the next larger floating-point number with the same data type and sparsity asp. The output is a 1-by-1 sparse matrix.

d = eps("like",p)
d = (1,1) 2.2204e-16

Input Arguments

collapse all

Input array, specified as a scalar, vector, matrix, or multidimensional array.dis the same size asx. For allx,eps(x) = eps(-x) = eps(abs(x)). Ifxis complex,dis the distance to the next larger floating-point number in magnitude. IfxisInforNaN, theneps(x)returnsNaN.

Data Types:double|single|duration
Complex Number Support:Yes

Output data type, specified as"double"or"single".

  • eps("double")is equivalent toepsandeps(1.0).

  • eps("single")is equivalent toeps(single(1.0))andsingle(2^-23).

Data Types:查r

Prototype, specified as a floating-point variable.

Data Types:double|single
Complex Number Support:Yes

Extended Capabilities

Version History

Introduced before R2006a