As implemented, EqualConstraint(expected).Within(x).Ulps works just
like a normal linear tolerance when expected is int, long, uint,
decimal, etc.
Is that what it should do? I'm not pushing one way or the other,
just asking. :-)
Charlie
Using Ulps on integral types is probably not a typical use case at all,
but that's the behavior I think is appropriate.
-
The Ulps-based methods in the Java Class Library do indeed only provide
overloads for float and double: Math.Ulp(float) and Math.Ulp(double).
That could either be because it's accepted practice that Ulps are only
used with floats and doubles or because creating an overload that does,
well, nothing and just returns its argument would be nonsensical.
Opinions?
> Charlie
>
>
>
-Markus-
From: nunit-...@googlegroups.com [mailto:nunit-...@googlegroups.com] On Behalf Of Thierry Lach
Sent: Wednesday, January 21, 2009 8:03 PM
To: nunit-...@googlegroups.com
Subject: [nunit-discuss] Re: Ulps and non-floating point values
Yup, that seems like a reasonable alternative.So we have (I think) three choices...1) Ignore it (basically we do that now)2) Convert the arguments to double if possible3) Throw
-Markus-Charlie
> I don't think 2) would be a good idea. For example, the
> smallest change an integer with value 1 can make is 1, but
> when seen as a double, there are 4,503,599,627,370,496 ulps
> between 1 and 2, for example, which is quite unexpected
> behvaior and outside of any reasonable tolerance you might specify.
OK, good point.
> So it's either 1) or 3), where my personal preference is
> option 1). It's not ignored, it just produces the exact same
> behavior as the linear comparison.
True, but one can view it either way. It's as if we had
a modifier "Units" with no impact at all.
Here's a rather pathological case. What should happen when
the third item is reached? What about the fourth?
object[] expected = new object[] { 1.0, 2.0, 3, TimeSpan.FromSeconds(20) };
object[] actual = new object[] { 1.00001, 2, 3, TimeSpan.FromSeconds(19) };
Assert.That(actual, Is.EqualTo(expected).Within(1).Ulps);
Charlie
So it's either 1) or 3), where my personal preference is option 1). It's not ignored, it just produces the exact same behavior as the linear comparison.True, but one can view it either way. It's as if we had a modifier "Units" with no impact at all. Here's a rather pathological case. What should happen when the third item is reached? What about the fourth? object[] expected = new object[] { 1.0, 2.0, 3, TimeSpan.FromSeconds(20) }; object[] actual = new object[] { 1.00001, 2, 3, TimeSpan.FromSeconds(19) }; Assert.That(actual, Is.EqualTo(expected).Within(1).Ulps);
-Markus-Charlie
Sent: Thursday, January 22, 2009 9:27 AM
An Ulps comparison is probably really not something the user would want
to do.
-Markus-
I did a review of all the literature I can find on the subject. While Markus' use ofUlps (units in the last place) with integers makes sense linguistically, all theliterature about it refers to floating point calculations.I hesitate to do something that would appear wrong to experts, even ifit might arguably make "common sense."
-Markus-Charlie
From: nunit-...@googlegroups.com [mailto:nunit-...@googlegroups.com] On Behalf Of Markus Ewald
Sent: Thursday, January 22, 2009 10:28 PM