ISEQUALFP: Check equality within floating point precision

버전 1.5.0.0 (1.74 KB) 작성자: Andrew Davis
Accepts two values, returns a logical indicating if they are equal within floating point precision
다운로드 수: 580
업데이트 날짜: 2012/5/22

라이선스 보기

ISEQUALFP Check two values for equality within floating point precision

It is widely known that floating point computation has a fundamental
limitation: not every value can be represented exactly. This can
lead to surprising results for those unfamiliar with this
limitation, especially since 'double' is MATLAB's default numerical
data type.

This function accepts two float values (single or double) or arrays
of floats, and returns a logical value indicating whether they
are equal within floating point precision. Mixed single and double
inputs will be evaluated based on single floating point precision.

Floating point accuracy reference:
http://blogs.mathworks.com/loren/2006/08/23/a-glimpse-into-floating-point-accuracy/

Usage:
yn = isequalfp(a,b)

a,b: floats or arrays of floats to compare

yn: logical scalar result indicating equality

Example:
a = 0.3;
b = 0.1*3;
isequal(a,b) % ans = 0
isequalfp(a,b) % ans = 1
c = a+2*eps(a) % c = 0.3000...
isequalfp(a,c) % ans = 0

See also: EPS, ISEQUAL

인용 양식

Andrew Davis (2024). ISEQUALFP: Check equality within floating point precision (https://www.mathworks.com/matlabcentral/fileexchange/36734-isequalfp-check-equality-within-floating-point-precision), MATLAB Central File Exchange. 검색됨 .

MATLAB 릴리스 호환 정보
개발 환경: R2011b
모든 릴리스와 호환
플랫폼 호환성
Windows macOS Linux
카테고리
Help CenterMATLAB Answers에서 Numbers and Precision에 대해 자세히 알아보기
도움

줌: Solve Magic Square

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!
버전 게시됨 릴리스 정보
1.5.0.0

Updated documentation to explain single/double behaviour

1.3.0.0

Syntax modified per Jan's suggestion

1.1.0.0

Description grammar and spacing corrections

1.0.0.0