I Can't Understand How Is_equal_approx Works!

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Matt101

Can someone explain to me how the is_equal_approx method works? I’ve read the documents, but I couldn’t quite understand how it works, especially regarding the function parameters.

:bust_in_silhouette: Reply From: klaas

the function will return true when a and b are equal or only have a very slight deviation.

The tolerance scales with size of the numbers. Higher numbers are treated with a higher tolerance when compared.

:bust_in_silhouette: Reply From: Wakatta

Floating Point Imprecision

It turns out that most fractional decimals cannot be represented precisely in binary and so there are a lot of fractional decimals which are approximated when stored in the computer causing what is known as floating point imprecision

An epsilon (Greek Letter) is used by is_equal_approx to determine if two floating points shall be considered equal or not and the function name is self explanatory hence the vague documentation.


is_equal_approx(1.39999, 1.4) # yes it is

Same should apply for Rects, Basis, Vectors, Transforms

The numbers in your example have too great of a difference. Also, there should be no capitalization (at least for engine version 3.5). Here:

is_equal_approx(1.399999999, 1.4) # yes it is

Now the difference should be less than epsilon, making the numbers “approximately equal”.

qdeanc | 2023-02-02 17:42

You input has been considered and Corrected

Wakatta | 2023-02-02 22:07