eps - Floating-point relative accuracy - MATLAB (original) (raw)
Floating-point relative accuracy
Syntax
Description
[d](#mw%5F446f45e0-ecaa-4512-b766-a85d3cbfd1fd) = eps
returns 2-52, which is the distance from1.0
to the next larger double-precision number.
[d](#mw%5F446f45e0-ecaa-4512-b766-a85d3cbfd1fd) = eps([x](#br8pqeh-1-x))
, wherex
has data type single
ordouble
, returns the positive distance fromabs(x)
to the next larger floating-point number of the same precision as x
. If x
has typeduration
, then eps(x)
returns the next larger duration
value. The command eps(1.0)
is equivalent to eps
.
[d](#mw%5F446f45e0-ecaa-4512-b766-a85d3cbfd1fd) = eps([datatype](#br8pqeh-1-datatype))
returns eps
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))
.
[d](#mw%5F446f45e0-ecaa-4512-b766-a85d3cbfd1fd) = 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 variablep
, with the same data type, sparsity, and complexity (real or complex) as p
.
Examples
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.
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.
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
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
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
Output data type, specified as "double"
or"single"
.
eps("double")
is equivalent toeps
andeps(1.0)
.eps("single")
is equivalent toeps(single(1.0))
andsingle(2^-23)
.
Data Types: char
Prototype, specified as a floating-point variable.
Data Types: double
| single
Complex Number Support: Yes
Output Arguments
Output array, returned as a scalar, vector, matrix, or multidimensional array.
Extended Capabilities
This function supports tall arrays with the limitations:
- Supported syntaxes are
eps(x)
andeps(like=p)
, where the underlying data type ofx
andp
must be a floating-point type.
For more information, see Tall Arrays.
Usage notes and limitations:
- When
FlushToZero
mode is enabled in Simulink, the smallest possible value returned byeps(x)
in a MATLAB Function Block isrealmin(class(x))
.
The eps
function supports GPU array input with these usage notes and limitations:
- Supported syntaxes are
eps(x)
andeps(like=p)
, where the underlying data type ofx
andp
must be a floating-point type.
For more information, see Run MATLAB Functions on a GPU (Parallel Computing Toolbox).
Usage notes and limitations:
- Supported syntaxes are
eps(x)
andeps(like=p)
, where the underlying data type ofx
andp
must be a floating-point type.
For more information, see Run MATLAB Functions with Distributed Arrays (Parallel Computing Toolbox).
Version History
Introduced before R2006a