1
0
mirror of https://github.com/opencv/opencv.git synced 2026-07-30 07:43:03 +04:00

fast_math: add extra perf/unit tests

Add a basic sanity test to verify the rounding functions
work as expected.

Likewise, extend the rounding performance test to cover the
additional float -> int fast math functions.
This commit is contained in:
Paul E. Murphy
2019-07-24 14:12:40 -05:00
parent 7295983964
commit b2135be594
2 changed files with 99 additions and 35 deletions
+54
View File
@@ -3923,5 +3923,59 @@ TEST(Core_SoftFloat, CvRound)
}
}
template<typename T>
static void checkRounding(T in, int outCeil, int outFloor)
{
EXPECT_EQ(outCeil,cvCeil(in));
EXPECT_EQ(outFloor,cvFloor(in));
/* cvRound is not expected to be IEEE compliant. The implementation
should round to one of the above. */
EXPECT_TRUE((cvRound(in) == outCeil) || (cvRound(in) == outFloor));
}
TEST(Core_FastMath, InlineRoundingOps)
{
struct
{
double in;
int outCeil;
int outFloor;
} values[] =
{
// Values are chosen to convert to binary float 32/64 exactly
{ 1.0, 1, 1 },
{ 1.5, 2, 1 },
{ -1.5, -1, -2}
};
for (int i = 0, maxi = sizeof(values) / sizeof(values[0]); i < maxi; i++)
{
checkRounding<double>(values[i].in, values[i].outCeil, values[i].outFloor);
checkRounding<float>((float)values[i].in, values[i].outCeil, values[i].outFloor);
}
}
TEST(Core_FastMath, InlineNaN)
{
EXPECT_EQ( cvIsNaN((float) NAN), 1);
EXPECT_EQ( cvIsNaN((float) -NAN), 1);
EXPECT_EQ( cvIsNaN(0.0f), 0);
EXPECT_EQ( cvIsNaN((double) NAN), 1);
EXPECT_EQ( cvIsNaN((double) -NAN), 1);
EXPECT_EQ( cvIsNaN(0.0), 0);
}
TEST(Core_FastMath, InlineIsInf)
{
// Assume HUGE_VAL is infinity. Strictly speaking, may not always be true.
EXPECT_EQ( cvIsInf((float) HUGE_VAL), 1);
EXPECT_EQ( cvIsInf((float) -HUGE_VAL), 1);
EXPECT_EQ( cvIsInf(0.0f), 0);
EXPECT_EQ( cvIsInf((double) HUGE_VAL), 1);
EXPECT_EQ( cvIsInf((double) -HUGE_VAL), 1);
EXPECT_EQ( cvIsInf(0.0), 0);
}
}} // namespace
/* End of file. */