# eps

Floating-point relative accuracy

## Syntax

``d = eps``
``d = eps(x)``
``d = eps(datatype)``
``d = eps("like",p)``

## Description

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

example

````d = eps(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)` returns `eps` according to the data type specified by `datatype`, which can be either `"double"` or `"single"`. The syntax `eps("double")` (default) is equivalent to `eps`, and `eps("single")` is equivalent to `eps(single(1.0))`.```

example

````d = eps("like",p)` 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) as `p`.```

example

## Examples

collapse all

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

`d = eps`
```d = 2.2204e-16 ```

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

Compute `log2(eps)`.

`d = log2(eps)`
```d = -52 ```

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

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

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

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

`d = eps("single")`
```d = single 1.1921e-07 ```

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

Compute `log2(eps("single"))`.

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

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.

`d = eps(single(10.0))`
```d = single 9.5367e-07 ```

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 = eps("like",p)`
```d = single 1.1921e-07 +0.0000e+00i ```

Create a 10-by-10 sparse matrix.

`p = sparse(10,10,pi);`

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 = eps("like",p)`
```d = sparse double (1,1) 2.2204e-16 ```

## Input Arguments

collapse all

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`, then `eps(x)` returns `NaN`.

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

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

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

• `eps("single")` is equivalent to `eps(single(1.0))` and `single(2^-23)`.

Data Types: `char`

Prototype, specified as a floating-point variable.

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

## Version History

Introduced before R2006a