Georgi Guninski on Tue, 28 Sep 2021 10:46:20 +0200


[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]

How to correctly check equality of non-integer numbers?


Given two non-integer numbers a1,a2 how to check they are
"logically" equal? Direct comparison `a1==a2` not always
works, e.g. this example:

? \p 100
? A0=20+30*I;k=5;a1=lfun(1,A0,k);a2=derivnum(x=A0,zeta(x),k);[a1==a2,abs(a1-a2)==0]
%8 = [0, 0]
? a1-a2
%9 = 2.2210727900800077785 E-114 + 8.030998757511428266 E-114*I

Observe that we might have numerical instability of two
expressions that are theoretically equal.

I expect the result should be something like:
? abs(a1-a2) < 10^-(default(realprecision)-4)
%15 = 1