1. 程式人生 > >【 MATLAB 】eps (浮點相對精度)簡介

【 MATLAB 】eps (浮點相對精度)簡介

目錄

 

eps

Syntax

Description

Accuracy in Double Precision

Accuracy in Single Precision


eps

Floating-point relative accuracy



Syntax

d = eps

d = eps(x)

d = eps(datatype)



Description

d = eps returns the distance from 1.0 to the next larger double-precision number, that is, 2^{-52}

.

d = eps返回從1.0到下一個更大的雙精度數的距離,即2^{-52}

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 typeduration, then eps(x) returns the next larger duration

 value. The command eps(1.0) is equivalent to eps.

d = eps(x),其中x具有資料型別single或double,返回從abs(x)到下一個與x相同精度的較大浮點數的正距離。 如果x具有typeduration,則eps(x)返回下一個更大的持續時間值。 命令eps(1.0)等同於eps。

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)).

d = eps(datatype)根據datatype指定的資料型別返回eps,資料型別可以是“double”或“single”。 語法eps('double')(預設)等同於eps,eps('single')等同於eps(single(1.0))。



Accuracy in Double Precision

clc
clear
close all
% Display the distance from 1.0 to the next largest 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.
% 
% Find the distance from 10.0 to the next largest double-precision number.

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

結果如下:

d =

   2.2204e-16


d =

   -52


d =

   1.7764e-15

 

Accuracy in Single Precision

clc
clear
close all
% Display the distance from 1.0 to the next largest 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.

% Find the distance from the single-precision representation of 10.0 to the next largest single-precision number.

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

結果如下:

d =

  single

  1.1921e-07


d =

  single

   -23


d =

  single

  9.5367e-07