Changeset View
Changeset View
Standalone View
Standalone View
head/tests/sys/sys/qmath_test.c
Show First 20 Lines • Show All 202 Lines • ▼ Show 20 Lines | |||||
* Test Q_QMULQ(3) by applying it to two random Q numbers and comparing | * Test Q_QMULQ(3) by applying it to two random Q numbers and comparing | ||||
* the result with its floating-point counterpart. | * the result with its floating-point counterpart. | ||||
*/ | */ | ||||
ATF_TC_WITHOUT_HEAD(qmulq_s64q); | ATF_TC_WITHOUT_HEAD(qmulq_s64q); | ||||
ATF_TC_BODY(qmulq_s64q, tc) | ATF_TC_BODY(qmulq_s64q, tc) | ||||
{ | { | ||||
s64q_t a_s64q, b_s64q, r_s64q; | s64q_t a_s64q, b_s64q, r_s64q; | ||||
double a_dbl, b_dbl, r_dbl, maxe_dbl, delta_dbl; | double a_dbl, b_dbl, r_dbl, maxe_dbl, delta_dbl; | ||||
#ifdef notyet | |||||
int64_t a_int, b_int; | int64_t a_int, b_int; | ||||
#endif | |||||
int error; | int error; | ||||
srandomdev(); | srandomdev(); | ||||
for (int i = 0; i < 10;) { | for (int i = 0; i < 10;) { | ||||
GENRAND(&a_s64q, INT64_MIN, UINT64_MAX); | GENRAND(&a_s64q, INT64_MIN, UINT64_MAX); | ||||
GENRAND(&b_s64q, INT64_MIN, UINT64_MAX); | GENRAND(&b_s64q, INT64_MIN, UINT64_MAX); | ||||
/* | /* | ||||
* XXX: We cheat a bit, to stand any chance of multiplying | * XXX: We cheat a bit, to stand any chance of multiplying | ||||
* without overflow. | * without overflow. | ||||
*/ | */ | ||||
error = Q_QDIVQ(&a_s64q, b_s64q); | error = Q_QDIVQ(&a_s64q, b_s64q); | ||||
if (error == EOVERFLOW || error == ERANGE) | if (error == EOVERFLOW || error == ERANGE) | ||||
continue; | continue; | ||||
ATF_CHECK_EQ(0, error); | ATF_CHECK_EQ(0, error); | ||||
/* | /* | ||||
* XXXLAS: Until Qmath handles precision normalisation, only | * XXXLAS: Until Qmath handles precision normalisation, only | ||||
* test with equal precision. | * test with equal precision. | ||||
*/ | */ | ||||
Q_SCVAL(b_s64q, Q_GCVAL(a_s64q)); | Q_SCVAL(b_s64q, Q_GCVAL(a_s64q)); | ||||
a_int = Q_GIVAL(a_s64q); | |||||
b_int = Q_GIVAL(b_s64q); | |||||
/* Q<op>Q testing. */ | /* Q<op>Q testing. */ | ||||
a_dbl = Q_Q2D(a_s64q); | a_dbl = Q_Q2D(a_s64q); | ||||
b_dbl = Q_Q2D(b_s64q); | b_dbl = Q_Q2D(b_s64q); | ||||
r_s64q = a_s64q; | r_s64q = a_s64q; | ||||
error = Q_QMULQ(&r_s64q, b_s64q); | error = Q_QMULQ(&r_s64q, b_s64q); | ||||
if (error == EOVERFLOW || error == ERANGE) | if (error == EOVERFLOW || error == ERANGE) | ||||
continue; | continue; | ||||
i++; | i++; | ||||
ATF_CHECK_EQ(0, error); | ATF_CHECK_EQ(0, error); | ||||
r_dbl = a_dbl * b_dbl; | r_dbl = a_dbl * b_dbl; | ||||
#ifdef notyet | #ifdef notyet | ||||
a_int = Q_GIVAL(a_s64q); | |||||
b_int = Q_GIVAL(b_s64q); | |||||
maxe_dbl = fabs(((1.0 / Q_NFBITS(a_s64q)) * (double)b_int) + | maxe_dbl = fabs(((1.0 / Q_NFBITS(a_s64q)) * (double)b_int) + | ||||
((1.0 / Q_NFBITS(b_s64q)) * (double)a_int)); | ((1.0 / Q_NFBITS(b_s64q)) * (double)a_int)); | ||||
#else | #else | ||||
maxe_dbl = QTEST_FFACTOR; | maxe_dbl = QTEST_FFACTOR; | ||||
#endif | #endif | ||||
delta_dbl = fabs(r_dbl - Q_Q2D(r_s64q)); | delta_dbl = fabs(r_dbl - Q_Q2D(r_s64q)); | ||||
ATF_CHECK_MSG(delta_dbl <= maxe_dbl, | ATF_CHECK_MSG(delta_dbl <= maxe_dbl, | ||||
"\tQMULQ(%10f * %10f): |%10f - %10f| = %10f " | "\tQMULQ(%10f * %10f): |%10f - %10f| = %10f " | ||||
"(max err %f)\n", | "(max err %f)\n", | ||||
Q_Q2D(a_s64q), Q_Q2D(b_s64q), Q_Q2D(r_s64q), r_dbl, | Q_Q2D(a_s64q), Q_Q2D(b_s64q), Q_Q2D(r_s64q), r_dbl, | ||||
delta_dbl, maxe_dbl); | delta_dbl, maxe_dbl); | ||||
} | } | ||||
} | } | ||||
/* | /* | ||||
* Test Q_QDIVQ(3) by applying it to two random Q numbers and comparing | * Test Q_QDIVQ(3) by applying it to two random Q numbers and comparing | ||||
* the result with its floating-point counterpart. | * the result with its floating-point counterpart. | ||||
*/ | */ | ||||
ATF_TC_WITHOUT_HEAD(qdivq_s64q); | ATF_TC_WITHOUT_HEAD(qdivq_s64q); | ||||
ATF_TC_BODY(qdivq_s64q, tc) | ATF_TC_BODY(qdivq_s64q, tc) | ||||
{ | { | ||||
s64q_t a_s64q, b_s64q, r_s64q; | s64q_t a_s64q, b_s64q, r_s64q; | ||||
double a_dbl, b_dbl, r_dbl, maxe_dbl, delta_dbl; | double a_dbl, b_dbl, r_dbl, maxe_dbl, delta_dbl; | ||||
int64_t a_int, b_int; | |||||
int error; | int error; | ||||
srandomdev(); | srandomdev(); | ||||
for (int i = 0; i < 10; i++) { | for (int i = 0; i < 10; i++) { | ||||
GENRAND(&a_s64q, INT64_MIN, UINT64_MAX); | GENRAND(&a_s64q, INT64_MIN, UINT64_MAX); | ||||
GENRAND(&b_s64q, INT64_MIN, UINT64_MAX); | GENRAND(&b_s64q, INT64_MIN, UINT64_MAX); | ||||
/* | /* | ||||
* XXXLAS: Until Qmath handles precision normalisation, only | * XXXLAS: Until Qmath handles precision normalisation, only | ||||
* test with equal precision. | * test with equal precision. | ||||
*/ | */ | ||||
Q_SCVAL(b_s64q, Q_GCVAL(a_s64q)); | Q_SCVAL(b_s64q, Q_GCVAL(a_s64q)); | ||||
a_int = Q_GIVAL(a_s64q); | |||||
b_int = Q_GIVAL(b_s64q); | |||||
/* Q<op>Q testing. */ | /* Q<op>Q testing. */ | ||||
a_dbl = Q_Q2D(a_s64q); | a_dbl = Q_Q2D(a_s64q); | ||||
b_dbl = Q_Q2D(b_s64q); | b_dbl = Q_Q2D(b_s64q); | ||||
r_s64q = a_s64q; | r_s64q = a_s64q; | ||||
error = Q_QDIVQ(&r_s64q, b_s64q); | error = Q_QDIVQ(&r_s64q, b_s64q); | ||||
ATF_CHECK_EQ(0, error); | ATF_CHECK_EQ(0, error); | ||||
Show All 17 Lines | |||||
* Test Q_QADDQ(3) by applying it to two random Q numbers and comparing | * Test Q_QADDQ(3) by applying it to two random Q numbers and comparing | ||||
* the result with its floating-point counterpart. | * the result with its floating-point counterpart. | ||||
*/ | */ | ||||
ATF_TC_WITHOUT_HEAD(qaddq_s64q); | ATF_TC_WITHOUT_HEAD(qaddq_s64q); | ||||
ATF_TC_BODY(qaddq_s64q, tc) | ATF_TC_BODY(qaddq_s64q, tc) | ||||
{ | { | ||||
s64q_t a_s64q, b_s64q, r_s64q; | s64q_t a_s64q, b_s64q, r_s64q; | ||||
double a_dbl, b_dbl, r_dbl, maxe_dbl, delta_dbl; | double a_dbl, b_dbl, r_dbl, maxe_dbl, delta_dbl; | ||||
int64_t a_int, b_int; | |||||
int error; | int error; | ||||
srandomdev(); | srandomdev(); | ||||
for (int i = 0; i < 10;) { | for (int i = 0; i < 10;) { | ||||
GENRAND(&a_s64q, INT64_MIN, UINT64_MAX); | GENRAND(&a_s64q, INT64_MIN, UINT64_MAX); | ||||
GENRAND(&b_s64q, INT64_MIN, UINT64_MAX); | GENRAND(&b_s64q, INT64_MIN, UINT64_MAX); | ||||
/* | /* | ||||
* XXXLAS: Until Qmath handles precision normalisation, only | * XXXLAS: Until Qmath handles precision normalisation, only | ||||
* test with equal precision. | * test with equal precision. | ||||
*/ | */ | ||||
Q_SCVAL(b_s64q, Q_GCVAL(a_s64q)); | Q_SCVAL(b_s64q, Q_GCVAL(a_s64q)); | ||||
a_int = Q_GIVAL(a_s64q); | |||||
b_int = Q_GIVAL(b_s64q); | |||||
/* Q<op>Q testing. */ | /* Q<op>Q testing. */ | ||||
a_dbl = Q_Q2D(a_s64q); | a_dbl = Q_Q2D(a_s64q); | ||||
b_dbl = Q_Q2D(b_s64q); | b_dbl = Q_Q2D(b_s64q); | ||||
r_s64q = a_s64q; | r_s64q = a_s64q; | ||||
error = Q_QADDQ(&r_s64q, b_s64q); | error = Q_QADDQ(&r_s64q, b_s64q); | ||||
if (error == EOVERFLOW || error == ERANGE) | if (error == EOVERFLOW || error == ERANGE) | ||||
Show All 20 Lines | |||||
* Test Q_QSUBQ(3) by applying it to two random Q numbers and comparing | * Test Q_QSUBQ(3) by applying it to two random Q numbers and comparing | ||||
* the result with its floating-point counterpart. | * the result with its floating-point counterpart. | ||||
*/ | */ | ||||
ATF_TC_WITHOUT_HEAD(qsubq_s64q); | ATF_TC_WITHOUT_HEAD(qsubq_s64q); | ||||
ATF_TC_BODY(qsubq_s64q, tc) | ATF_TC_BODY(qsubq_s64q, tc) | ||||
{ | { | ||||
s64q_t a_s64q, b_s64q, r_s64q; | s64q_t a_s64q, b_s64q, r_s64q; | ||||
double a_dbl, b_dbl, r_dbl, maxe_dbl, delta_dbl; | double a_dbl, b_dbl, r_dbl, maxe_dbl, delta_dbl; | ||||
int64_t a_int, b_int; | |||||
int error; | int error; | ||||
srandomdev(); | srandomdev(); | ||||
for (int i = 0; i < 10; i++) { | for (int i = 0; i < 10; i++) { | ||||
GENRAND(&a_s64q, INT64_MIN, UINT64_MAX); | GENRAND(&a_s64q, INT64_MIN, UINT64_MAX); | ||||
GENRAND(&b_s64q, INT64_MIN, UINT64_MAX); | GENRAND(&b_s64q, INT64_MIN, UINT64_MAX); | ||||
/* | /* | ||||
* XXXLAS: Until Qmath handles precision normalisation, only | * XXXLAS: Until Qmath handles precision normalisation, only | ||||
* test with equal precision. | * test with equal precision. | ||||
*/ | */ | ||||
Q_SCVAL(b_s64q, Q_GCVAL(a_s64q)); | Q_SCVAL(b_s64q, Q_GCVAL(a_s64q)); | ||||
a_int = Q_GIVAL(a_s64q); | |||||
b_int = Q_GIVAL(b_s64q); | |||||
/* Q<op>Q testing. */ | /* Q<op>Q testing. */ | ||||
a_dbl = Q_Q2D(a_s64q); | a_dbl = Q_Q2D(a_s64q); | ||||
b_dbl = Q_Q2D(b_s64q); | b_dbl = Q_Q2D(b_s64q); | ||||
r_s64q = a_s64q; | r_s64q = a_s64q; | ||||
error = Q_QSUBQ(&r_s64q, b_s64q); | error = Q_QSUBQ(&r_s64q, b_s64q); | ||||
ATF_CHECK_EQ(0, error); | ATF_CHECK_EQ(0, error); | ||||
▲ Show 20 Lines • Show All 259 Lines • Show Last 20 Lines |