-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
bug in dplyr::near
?
#6921
Comments
Slightly simpler reprex: dplyr::near(1.1 * 100 * 10^5, 110 * 10^5)
#> [1] TRUE
dplyr::near(1.1 * 100 * 10^6, 110 * 10^6)
#> [1] FALSE
all.equal(1.1 * 100 * 10^6, 110 * 10^6)
#> [1] TRUE |
I don't think options(digits = 22)
110
#> [1] 110
1.1 * 100
#> [1] 110.0000000000000142109
110 * 10^200
#> [1] 1.099999999999999891922e+202
1.1 * 100 * 10^200
#> [1] 1.100000000000000109476e+202
(1.1 * 100 * 10^200) - (110 * 10^200)
#> [1] 2.175541218577478036233e+186
# are they "near"?
((1.1 * 100 * 10^200) - (110 * 10^200)) < sqrt(.Machine$double.eps)
#> [1] FALSE
|
I think However, the documentation is misleading.
The description suggests that the functions solves the issue of testing floating point numbers on equality. The example above show that this is not the case. Another example is:
Thus I would propose that the description of |
@etiennebacher @DavisVaughan @bundfussr Thank you so much for the discussion! |
|
It's worth noting that all.equal(10^-8, 2 * 10^-8)
#> [1] TRUE
all.equal(2 * 10^-8, 10^-8)
#> [1] "Mean relative difference: 0.5" I typically use something similar to the below function (written in C++).
Created on 2023-10-20 with reprex v2.0.2 |
Is the following example a bug in
near
?Originally posted by @bundfussr in pharmaverse/admiral#2060 (comment)
The same example works as expected with
base::all.equal()
The text was updated successfully, but these errors were encountered: