math_conformance.rs revision 648a1c137663ef7207684d0d7009dd5518942111
1#include "shared.rsh"
2
3// Testing math conformance
4
5static bool test_rootn() {
6    bool failed = false;
7
8    // rootn(x, 0) -> _inf
9    _RS_ASSERT(isposinf(rootn(1.0f, 0)));
10
11    // rootn(+/-0, n) -> +/-inf for odd n < 0
12    _RS_ASSERT(isposinf(rootn(0.f, -3)));
13    _RS_ASSERT(isneginf(rootn(-0.f, -3)));
14
15    // rootn(+/-0, n) -> +inf for even n < 0
16    _RS_ASSERT(isposinf(rootn(0.f, -8)));
17    _RS_ASSERT(isposinf(rootn(-0.f, -8)));
18
19    // rootn(+/-0, n) -> +/-0 for odd n > 0
20    _RS_ASSERT(isposzero(rootn(0.f, 3)));
21    _RS_ASSERT(isnegzero(rootn(-0.f, 3)));
22
23    // rootn(+/-0, n) -> +0 for even n > 0
24    _RS_ASSERT(isposzero(rootn(0.f, 8)));
25    _RS_ASSERT(isposzero(rootn(-0.f, 8)));
26
27    // rootn(x, n) -> NaN for x < 0 and even n
28    _RS_ASSERT(isnan(rootn(-10000.f, -4)));
29    _RS_ASSERT(isnan(rootn(-10000.f, 4)));
30
31    // rootn(x, n) -> value for x < 0 and odd n
32    _RS_ASSERT(!isnan(rootn(-10000.f, -3)));
33    _RS_ASSERT(!isnan(rootn(-10000.f, 3)));
34
35    if (failed) {
36        rsDebug("test_rootn FAILED", -1);
37    }
38    else {
39        rsDebug("test_rootn PASSED", 0);
40    }
41
42    return failed;
43}
44
45void math_conformance_test() {
46    bool failed = false;
47    failed |= test_rootn();
48
49    if (failed) {
50        rsDebug("math_conformance_test FAILED", -1);
51        rsSendToClientBlocking(RS_MSG_TEST_FAILED);
52    }
53    else {
54        rsDebug("math_conformance_test PASSED", 0);
55        rsSendToClientBlocking(RS_MSG_TEST_PASSED);
56    }
57}
58