Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign upAdd RFC: approx-asserts #897
Conversation
dhardy
force-pushed the
dhardy:master
branch
from
b4aa794
to
b676241
Feb 23, 2015
This comment has been minimized.
This comment has been minimized.
// You could do something different with macros to differentiate the
// relative and absolute. I'm not sure if `=` works with macros...expressions
// usually just evaluate...not really experience with this type...
assert_tol!(1.003e8f32, 1e8f32, rel = abs = 1e-2f32);
assert_tol!(1.003e8f32, 1e8f32, rel = .01, abs = .1); |
alexcrichton
referenced this pull request
Feb 24, 2015
Closed
Improved assert_approx_eq!() + doc #21888
This comment has been minimized.
This comment has been minimized.
|
I’d prefer just having an I think that if we do get a macro like this, we should get a method on floats like it as well. Having a macro to assert something but not a simple method to test it would be pretty ridiculous. |
This comment has been minimized.
This comment has been minimized.
|
@P1start do you say this out of simple reasoning or experience? I'm not saying you're wrong, but the only time I have wanted approximate equality outside of an assertion is when error-handling user input of the form "I require a list of numbers whose sum must be 1", at which point it is usually clearer to write something like Other than that, your suggestion has two issues: (minor) it's longer to type and (major) poor error messages:
panics with message
but what's the value of |
This comment has been minimized.
This comment has been minimized.
|
@mdinger thanks for the hint, will consider |
nrc
assigned
brson
and unassigned
brson
Mar 5, 2015
This comment has been minimized.
This comment has been minimized.
|
Thanks for the PR! In general, we're working right now to cut down the standard library to a conservative core that we're happy to commit to. While these macros seem useful, there's not in my mind a strong reason to introduce them into the standard library and prelude right this second -- in general, it's better for this kind of thing to begin its life in the crates.io ecosystem and gradually migrate into |
aturon
closed this
Mar 5, 2015
This comment has been minimized.
This comment has been minimized.
|
Sounds like good advice, cheers. |
dhardy commentedFeb 23, 2015
assert_approxmacro to libstd preludeassert_tolmacro to libstd preludeRendered