[erlang-questions] how: best way to deal with floats in eunit?
Richard Carlsson
richardc@REDACTED
Tue Aug 12 21:22:46 CEST 2008
Tim Fletcher wrote:
> And similarly, would there be a better way to handle my original
> problem, instead of just unpacking the data structure and using such
> an assertion? I don't usually deal with floats, so I don't know what
> the typical approach would be.
Your example was that you'd get "something like [{1, 0.1}]", but do
you only require that e.g. {1, 2, 3} compares equal to {1.0, 2.0, 3.0},
i.e., that the only differences that may occur are due to integer <->
float conversions, or do you need to handle actual computed values, so
that {1,2,3} should compare equal to {1.0000001,2.0000001,3.0000001}?
In the first case, a simple == comparison on the whole term should be
enough. In the latter case you really have to unpack the structure and
handle each comparison separately.
/Richard
More information about the erlang-questions
mailing list