Skip to content
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

issue warning when user performs an exact comparison on reals #158

Open
olwmc opened this issue Apr 7, 2022 · 3 comments
Open

issue warning when user performs an exact comparison on reals #158

olwmc opened this issue Apr 7, 2022 · 3 comments
Labels
enhancement Features that are directly related to the core tenet of Asteroid

Comments

@olwmc
Copy link
Collaborator

olwmc commented Apr 7, 2022

Because python's underlying floating point arithmetic has precision errors, the following program prints out false:

load system io.
io @println ( (.1 + .1 + .1) == .3 ).

All we would really need to do is to have a check in our comparators for real and use the math.isclose() if we wanted a more natural model for floating point arithmetic. Alternatively, we could implement our own isclose to mirror the underlying implementation.

@olwmc olwmc added the annoying label Apr 7, 2022
@lutzhamel
Copy link
Collaborator

That's real bad. I thought, may be this is due to the way we might be interacting with Python but no,

lutz$ python3
Python 3.8.9 (default, Oct 26 2021, 07:25:53) 
[Clang 13.0.0 (clang-1300.0.29.30)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> 0.1 + 0.1 + 0.1 == 0.3
False
>>> 

Ouch!

@olwmc
Copy link
Collaborator Author

olwmc commented Apr 7, 2022

By extension this is true with standard C under both gcc and clang (The only two I've tested so far)!!

What do you all think the best solution here is? Have some standard epsilon we work with for tolerances or just give users something akin to isclose?

@lutzhamel lutzhamel added this to the Release 1.1.0 milestone May 28, 2022
@lutzhamel lutzhamel removed this from the Release 1.1.0 milestone Aug 6, 2022
@lutzhamel
Copy link
Collaborator

The function isclose already exists in our math module. Perhaps we should issue a warning when folks try to do an exact comparison on reals...

@lutzhamel lutzhamel changed the title Need to account for python precision errors in floating point arithmetic issue warning when user performs an exact comparison on reals Feb 17, 2023
@lutzhamel lutzhamel added the enhancement Features that are directly related to the core tenet of Asteroid label Feb 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Features that are directly related to the core tenet of Asteroid
Projects
None yet
Development

No branches or pull requests

2 participants