summaryrefslogtreecommitdiffstats
path: root/tests/math_data_test.h
diff options
context:
space:
mode:
authorJingwei Zhang <jingwei.zhang@intel.com>2014-09-02 21:39:14 +0800
committerMingwei Shi <mingwei.shi@intel.com>2015-02-14 00:56:46 +0800
commit56b2b2916b72eb21352c7aed529e0deeb5582072 (patch)
tree1299d64a93aec1d48f3abe304a8db75668a9dad1 /tests/math_data_test.h
parentf9fb52ab309c97d5b2ef4f8e1daff3eed4cf4024 (diff)
downloadbionic-56b2b2916b72eb21352c7aed529e0deeb5582072.zip
bionic-56b2b2916b72eb21352c7aed529e0deeb5582072.tar.gz
bionic-56b2b2916b72eb21352c7aed529e0deeb5582072.tar.bz2
Accuracy tests for libm
This patch adds more tests for math functions to address coverage issue of math functions discussed in: https://android-review.googlesource.com/#/c/49653/ https://android-review.googlesource.com/#/c/94780/ These are data sets used in regression tests for the Intel the math library (libm). They were collected over a long period of testing various libm implementations. The data sets contain function specific data (special and corner cases such as +/-0, maximum/minimum normalized numbers, +/-infinity, QNaN/SNaN, maximum/minimum denormal numbers, arguments that would produce close to overflow/underflow results, known hard-to-round cases, etc), implementation specific data (arguments close to table look-up values for different polynomial approximations, worst cases for range reduction algorithms) and other data with interesting bit patterns. The reference values are computed with Maple and were converted into hexadecimal format. Change-Id: I7177c282937369eae98f25d02134e4fc3beadde8 Signed-off-by: Jingwei Zhang <jingwei.zhang@intel.com> Signed-off-by: Mingwei Shi <mingwei.shi@intel.com>
Diffstat (limited to 'tests/math_data_test.h')
-rw-r--r--tests/math_data_test.h103
1 files changed, 103 insertions, 0 deletions
diff --git a/tests/math_data_test.h b/tests/math_data_test.h
index f3d25ef..8aa2bf1 100644
--- a/tests/math_data_test.h
+++ b/tests/math_data_test.h
@@ -24,6 +24,12 @@ struct data_1_1_t {
T1 input;
};
+template <typename T1>
+struct data_int_1_t {
+ int expected;
+ T1 input;
+};
+
template <typename RT, typename T1, typename T2>
struct data_1_2_t {
RT expected;
@@ -38,6 +44,29 @@ struct data_2_1_t {
T input;
};
+template <typename RT1, typename T>
+struct data_1_int_1_t {
+ RT1 expected1;
+ int expected2;
+ T input;
+};
+
+template <typename RT1, typename T1, typename T2>
+struct data_1_int_2_t {
+ RT1 expected1;
+ int expected2;
+ T1 input1;
+ T2 input2;
+};
+
+template <typename RT, typename T1, typename T2, typename T3>
+struct data_1_3_t {
+ RT expected;
+ T1 input1;
+ T2 input2;
+ T3 input3;
+};
+
template <typename T> union fp_u;
template <> union fp_u<float> {
@@ -117,6 +146,17 @@ void DoMathDataTest(data_1_1_t<RT, T> (&data)[N], RT f(T)) {
}
}
+// Runs through the array 'data' applying 'f' to each of the input values
+// and asserting that the result is within ULP ulps of the expected value.
+// For testing a (double) -> int function like ilogb(3).
+template <size_t ULP, typename T, size_t N>
+void DoMathDataTest(data_int_1_t<T> (&data)[N], int f(T)) {
+ fesetenv(FE_DFL_ENV);
+ for (size_t i = 0; i < N; ++i) {
+ EXPECT_EQ(data[i].expected, f(data[i].input)) << "Failed on element " << i;
+ }
+}
+
// Runs through the array 'data' applying 'f' to each of the pairs of input values
// and asserting that the result is within ULP ulps of the expected value.
// For testing a (double, double) -> double function like pow(3).
@@ -146,3 +186,66 @@ void DoMathDataTest(data_2_1_t<RT1, RT2, T1> (&data)[N], void f(T1, RT1*, RT2*))
EXPECT_PRED_FORMAT2(predicate2, data[i].expected2, out2) << "Failed on element " << i;
}
}
+
+// Runs through the array 'data' applying 'f' to each of the input values
+// and asserting that the results are within ULP ulps of the expected values.
+// For testing a (double, double*) -> double function like modf(3).
+template <size_t ULP, typename RT1, typename RT2, typename T1, size_t N>
+void DoMathDataTest(data_2_1_t<RT1, RT2, T1> (&data)[N], RT1 f(T1, RT2*)) {
+ fesetenv(FE_DFL_ENV);
+ FpUlpEq<ULP, RT1> predicate1;
+ FpUlpEq<ULP, RT2> predicate2;
+ for (size_t i = 0; i < N; ++i) {
+ RT1 out1;
+ RT2 out2;
+ out1 = f(data[i].input, &out2);
+ EXPECT_PRED_FORMAT2(predicate1, data[i].expected1, out1) << "Failed on element " << i;
+ EXPECT_PRED_FORMAT2(predicate2, data[i].expected2, out2) << "Failed on element " << i;
+ }
+}
+
+// Runs through the array 'data' applying 'f' to each of the input values
+// and asserting that the results are within ULP ulps of the expected values.
+// For testing a (double, int*) -> double function like frexp(3).
+template <size_t ULP, typename RT1, typename T1, size_t N>
+void DoMathDataTest(data_1_int_1_t<RT1, T1> (&data)[N], RT1 f(T1, int*)) {
+ fesetenv(FE_DFL_ENV);
+ FpUlpEq<ULP, RT1> predicate1;
+ for (size_t i = 0; i < N; ++i) {
+ RT1 out1;
+ int out2;
+ out1 = f(data[i].input, &out2);
+ EXPECT_PRED_FORMAT2(predicate1, data[i].expected1, out1) << "Failed on element " << i;
+ EXPECT_EQ(data[i].expected2, out2) << "Failed on element " << i;
+ }
+}
+
+// Runs through the array 'data' applying 'f' to each of the input values
+// and asserting that the results are within ULP ulps of the expected values.
+// For testing a (double, double, int*) -> double function like remquo(3).
+template <size_t ULP, typename RT1, typename T1, typename T2, size_t N>
+void DoMathDataTest(data_1_int_2_t<RT1, T1, T2> (&data)[N], RT1 f(T1, T2, int*)) {
+ fesetenv(FE_DFL_ENV);
+ FpUlpEq<ULP, RT1> predicate1;
+ for (size_t i = 0; i < N; ++i) {
+ RT1 out1;
+ int out2;
+ out1 = f(data[i].input1, data[i].input2, &out2);
+ EXPECT_PRED_FORMAT2(predicate1, data[i].expected1, out1) << "Failed on element " << i;
+ EXPECT_EQ(data[i].expected2, out2) << "Failed on element " << i;
+ }
+}
+
+// Runs through the array 'data' applying 'f' to each of the pairs of input values
+// and asserting that the result is within ULP ulps of the expected value.
+// For testing a (double, double, double) -> double function like fma(3).
+template <size_t ULP, typename RT, typename T1, typename T2, typename T3, size_t N>
+void DoMathDataTest(data_1_3_t<RT, T1, T2, T3> (&data)[N], RT f(T1, T2, T3)) {
+ fesetenv(FE_DFL_ENV);
+ FpUlpEq<ULP, RT> predicate;
+ for (size_t i = 0; i < N; ++i) {
+ EXPECT_PRED_FORMAT2(predicate,
+ data[i].expected, f(data[i].input1, data[i].input2, data[i].input3)) << "Failed on element " << i;
+ }
+}
+