ISEQUALFP: Check equality within floating point precision

Accepts two values, returns a logical indicating if they are equal within floating point precision


Updated 22 May 2012

View License

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:

yn = isequalfp(a,b)

a,b: floats or arrays of floats to compare

yn: logical scalar result indicating equality

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

Cite As

Andrew Davis (2023). ISEQUALFP: Check equality within floating point precision (, MATLAB Central File Exchange. Retrieved .

MATLAB Release Compatibility
Created with R2011b
Compatible with any release
Platform Compatibility
Windows macOS Linux

Inspired: Solve Magic Square

Community Treasure Hunt

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

Start Hunting!
Version Published Release Notes

Updated documentation to explain single/double behaviour

Syntax modified per Jan's suggestion

Description grammar and spacing corrections