On 10 July 2010 17:40, Misha Koshelev misha680@gmail.com wrote:
On Sat, 2010-07-10 at 07:40 +0100, Reece Dunn wrote:
On 10 July 2010 03:40, Misha Koshelev misha680@gmail.com wrote:
Ok that makes sense.
What about in the case of something like this:
/* http://www.cygnus-software.com/papers/comparingfloats/comparingfloats.htm * "I think the answer is 10,000 but since floating point math is imperfect I’ll accept the maxUlps floats above and the maxUlps floats below that value." */ static BOOLEAN AlmostEqual2sComplement(float A, float B, int maxUlps) { int aInt, bInt, intDiff; /* Make sure maxUlps is non-negative and small enough that the * default NAN won't compare as equal to anything. */ assert(maxUlps > 0 && maxUlps < 4 * 1024 * 1024);
Is assert ok here or do I need to change it to some kind of skip statement as well?
The assert should be ok here provided that maxUlps does not come from some function -- that is, it is constant and will trigger on all systems.
Assert statements are not forbidden in tests (there are some already in various tests), it's just that if they trigger as a result of the system as part of calls under test, they make it difficult to track down what is failing and why by looking at the test results. If the asserts are triggered on any system because they are the result of programmer error (e.g. typo) should be fine.
- Reece