-
Notifications
You must be signed in to change notification settings - Fork 28
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
Small numbers don't work with some logical operators #351
Comments
Yes, that happens here: https://github.com/r-quantities/units/blob/main/src/udunits.cpp#L115 , and I'm not sure that is a good idea. What do you think, @Enchufa2 ? |
The thing is... we need to convert units in order to compare values, but udunits2 has float precision. So that line referenced above is set so that things like We could detect cases in which no conversion is involved and avoid using float tolerance in such cases. But then we are just chasing individual cases, and the example above would be |
I'm pretty sure that also for using floats, |
For 3.6 km/h sometimes not equaling 1 m/s we could refer to R faq 7.31. |
Ok, since R users should be accustomed to make comparisons with tolerances via |
BTW, you are probably thinking of doubles, not floats: Rcpp::evalCpp("std::numeric_limits<float>::epsilon()")
#> [1] 1.192093e-07
Rcpp::evalCpp("std::numeric_limits<double>::epsilon()")
#> [1] 2.220446e-16 But anyway I should have scaled that epsilon as the thread you link above points out. I left the proper code commented in #353 just in case we need to revisit this in the future in the C++ side. |
Not if you consider that before comparison a conversion takes place that depends on the order of arguments (right is converted to the left). So the conversion is different in both cases. |
Yes, of course, but the user doesn't necessarily know that this happens, so I expect this to be surprising. |
I discovered a wierd bug where logical comparisons with small numbers silently fail.
Example:
Here is a little script to get more details
It seems that in this case, when the magnitude of the number on the RHS is 1e-7 or less, the comparison fails.
I am running R 4.3.1 and units-0.8-2 on the latest Linux Mint Cinnamon.
The text was updated successfully, but these errors were encountered: