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

Watch out for approx in Julia when compared to zero #115

Open
mykelk opened this issue Nov 16, 2024 · 1 comment
Open

Watch out for approx in Julia when compared to zero #115

mykelk opened this issue Nov 16, 2024 · 1 comment
Assignees

Comments

@mykelk
Copy link
Contributor

mykelk commented Nov 16, 2024

(Thanks to Kathryn Lesh)

We use this in Alg 19.2, which is pretty much the same as exact equality comparison with 0. Comparison to 0 is handled a bit differently. See, for example, this link and links from there to the Julia issue tracker and justification. The kind of behavior referenced is something like this:

julia> 1.2e-16≈0

false

julia> 1+1.2e-16≈1

true

julia> isapprox(1.2e-16, 0.0; atol=1e-15, rtol=0)

true
@mykelk mykelk self-assigned this Nov 16, 2024
@tawheeler
Copy link
Collaborator

It sounds like the takeaway is that isapprox defaults to rtol::Real=sqrt(eps), atol::Real=0, and for zero the relative tolerance is zero. Good to know!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants