eps - Floating-point relative accuracy - MATLAB (original) (raw)

Floating-point relative accuracy

Syntax

Description

d = eps returns 2-52, which is the distance from 1.0 to the next larger double-precision number.

example

d = eps([x](#br8pqeh-1-x)), where x has data type single or double, returns the positive distance from abs(x) to the next larger floating-point number of the same precision as x. If x has type duration, then eps(x) returns the next larger duration value. The command eps(1.0) is equivalent to eps.

example

d = eps([datatype](#br8pqeh-1-datatype)) returnseps according to the data type specified bydatatype, which can be either "double" or"single". The syntax eps("double") (default) is equivalent to eps, andeps("single") is equivalent toeps(single(1.0)).

example

d = eps("like",[p](#mw%5F86fcb61c-1557-4b41-9962-92a6041aeb2f)) returns the positive distance from 1.0 to the next larger floating-point number of the same precision as the floating-point variable p, with the same data type, sparsity, and complexity (real or complex) asp.

example

Examples

collapse all

Accuracy in Double Precision

Return the distance from 1.0 to the next larger double-precision number.

eps is equivalent to eps(1.0) and eps("double").

Compute log2(eps).

In base 2, eps is equal to 2^-52.

Return the distance from 10.0 to the next larger double-precision number.

Accuracy in Single Precision

Return the distance from 1.0 to the next larger single-precision number.

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

Compute log2(eps("single")).

In base 2, single-precision eps is equal to 2^-23.

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

Specify Data Type and Complexity from Existing Array

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

First, create a complex vector of single data type.

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

Return the distance from 1.0 to the next larger floating-point number as a scalar that is complex like p.

d = single

1.1921e-07 +0.0000e+00i

Specify Sparsity from Existing Array

Create a 10-by-10 sparse matrix.

Return the distance from 1.0 to the next larger floating-point number with the same data type and sparsity as p. The output is a 1-by-1 sparse matrix.

d = sparse double (1,1) 2.2204e-16

Input Arguments

collapse all

x — Input array

scalar | vector | matrix | multidimensional array

Input array, specified as a scalar, vector, matrix, or multidimensional array. d is the same size as x. For all x, eps(x) = eps(-x) = eps(abs(x)). If x is complex, d is the distance to the next larger floating-point number in magnitude. If x is Inf or NaN, theneps(x) returns NaN.

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

datatype — Output data type

"double" (default) | "single"

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

Data Types: char

p — Prototype

floating-point variable

Prototype, specified as a floating-point variable.

Data Types: double | single
Complex Number Support: Yes

Extended Capabilities

Tall Arrays

Calculate with arrays that have more rows than fit in memory.

This function supports tall arrays with the limitations:

For more information, see Tall Arrays.

C/C++ Code Generation

Generate C and C++ code using MATLAB® Coder™.

Usage notes and limitations:

Thread-Based Environment

Run code in the background using MATLAB® backgroundPool or accelerate code with Parallel Computing Toolbox™ ThreadPool.

This function fully supports thread-based environments. For more information, see Run MATLAB Functions in Thread-Based Environment.

GPU Arrays

Accelerate code by running on a graphics processing unit (GPU) using Parallel Computing Toolbox™.

The eps function supports GPU array input with these usage notes and limitations:

For more information, see Run MATLAB Functions on a GPU (Parallel Computing Toolbox).

Distributed Arrays

Partition large arrays across the combined memory of your cluster using Parallel Computing Toolbox™.

Usage notes and limitations:

For more information, see Run MATLAB Functions with Distributed Arrays (Parallel Computing Toolbox).

Version History

Introduced before R2006a