You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hello! First, thanks for the great unit testing library. I really enjoy seeing all my tests compile instantly and having such a pleasant library to work with.
I'd like to suggest some enhancements to the floating point asserts. I'm aware of issue #147. A pretty reasonable way to deal with the issue with zero pointed out in that issue is to use a relative and absolute tolerance together. Consider what happens here:
rtol = 1e-10 # Relative tolerance
x = 0
y = 1e-12
abs(x - y)/max(abs(x), abs(y)) < rtol # False!
When developing numerical code, these are the kinds of tests I like to use. It'd be very helpful if this was baked into Cgreen.
It is also a little unconventional (when developing numerical code) to think about tolerances in terms of significant figures. Tolerances will just be specified using scientific notation; e.g., double machine epsilon ≈ 2.2e-16. It would be nice to be able to specify tolerances this way.
Altogether, I'd like to be able to write the following code:
Thanks for your suggestion! It sounds very reasonable to me. I'm not at all into numeric software so I have limited experience with what would be natural for them (you).
My immediate thought is how to combine the two tolerance models. I think we could need help to figure that out.
You might already have figured out that the essential code is in the functions doubles_are_equal()
I suppose the basics would be to have your double_relative_tolerance() and double_absolute_tolerance() set a flag to know that the tolerance should be calculated using "scientific" rather than "digits". And the accuracy() function would do that calculation differently in the two cases.
And of course we would need to figure out what we want to do when someone calls both ...tolerance_is() and significant_digits...().
Thanks for the quick response. I threw together a PR with a rough draft implementation. I tested this out with a library I'm working on, and it works more or less as I'd like.
I responded in more detail to some of your comments in my PR.
Hello! First, thanks for the great unit testing library. I really enjoy seeing all my tests compile instantly and having such a pleasant library to work with.
I'd like to suggest some enhancements to the floating point asserts. I'm aware of issue #147. A pretty reasonable way to deal with the issue with zero pointed out in that issue is to use a relative and absolute tolerance together. Consider what happens here:
Okay... Let's define an absolute tolerance:
When developing numerical code, these are the kinds of tests I like to use. It'd be very helpful if this was baked into Cgreen.
It is also a little unconventional (when developing numerical code) to think about tolerances in terms of significant figures. Tolerances will just be specified using scientific notation; e.g., double machine epsilon ≈ 2.2e-16. It would be nice to be able to specify tolerances this way.
Altogether, I'd like to be able to write the following code:
Does this sound reasonable?
Thanks again for Cgreen!
The text was updated successfully, but these errors were encountered: