-
Notifications
You must be signed in to change notification settings - Fork 185
Tolerant comparison of real numbers #327
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Personally, I would be very interested in that. The naive approach that I currently use in my codes is the following: elemental logical function eqreal(real1, real2)
real(wp), intent(in) :: real1, real2
eqreal = abs(real1 - real2) < spacing( max( abs(real1), abs(real2) ) )
end function eqreal I would be curious to learn what a proper approach would be. |
I am not sure if there is a proper approach ;). The best I can think of is a well-chosen tolerance and that may actually be dependent on the application. The code I was referring predates Fortran 90, by the way, but it is definitely worth considering, if only because it will provide some common ground based on much prior work. |
I think this is a partial duplicate of #145. We can keep this issue open for the well-behaved |
Indeed, the collection of functions I have includes the ones described
there.
Op vr 26 feb. 2021 om 17:35 schreef Ivan Pribec <[email protected]>:
… I think this is a partial duplicate of #145
<#145>.
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#327 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAN6YRYLEJBQDN2OKVMV6RTTA7ETHANCNFSM4YIL5PBA>
.
|
I think it is indeed something for stdlib. It could even be used inside stdlib for the different tests with real values (and for which we already got multiple issues/discussions). |
I attach the original source code eps_f90.txt - I have not take the opportunity yet to convert it to a modern package, so it is really old-school :). However, the output from the program may be of interest to give better insight: EPS= 0.22204460D-15 3CB0000000000000, EPS3= 0.66613381D-15 3CC8000000000000 X=0.11D0, Y=X*11.D0-X-0.1D0, Z=1.D0 |
Some feedback from the Fortran call:
|
What about an API similar to |
It's called Interface Documentation Implementation |
GNU GSL also has this functionality in the function Interface Documentation Implementation (License: GPL) |
This blog post discuss 4 different ways to compare floating-point numbers: https://codingnest.com/the-little-things-comparing-floating-point-numbers/ |
A relevant project is https://github.com/suzuyuyuyu/fortran-approx @suzuyuyuyu |
I have the source for a set of comparison functions and other functions such as floor and ceil that take into account that real numbers are not as well-behaved as, say, integers, by taking a margin into account. The source comes from Skip Knoble, once quite active on comp.lang.fortran, and builds on work by Hindmarsh and others.
Is this something useful for stdlib? The source needs to be updated to the current standard, but I can do that :).
The text was updated successfully, but these errors were encountered: