summaryrefslogtreecommitdiffstats
path: root/tests/RenderScriptTests/RSTest_CompatLib/src/com/android/rs/test/math_conformance.rs
blob: 2d62f34338bc3f3772987b214bcf9f86f4915f43 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#include "shared.rsh"

// Testing math conformance

static bool test_rootn() {
    bool failed = false;

    // rootn(x, 0) -> NaN
    _RS_ASSERT(isnan(rootn(1.0f, 0)));

    // rootn(+/-0, n) -> +/-inf for odd n < 0
    _RS_ASSERT(isposinf(rootn(0.f, -3)));
    _RS_ASSERT(isneginf(rootn(-0.f, -3)));

    // rootn(+/-0, n) -> +inf for even n < 0
    _RS_ASSERT(isposinf(rootn(0.f, -8)));
    _RS_ASSERT(isposinf(rootn(-0.f, -8)));

    // rootn(+/-0, n) -> +/-0 for odd n > 0
    _RS_ASSERT(isposzero(rootn(0.f, 3)));
    _RS_ASSERT(isnegzero(rootn(-0.f, 3)));

    // rootn(+/-0, n) -> +0 for even n > 0
    _RS_ASSERT(isposzero(rootn(0.f, 8)));
    _RS_ASSERT(isposzero(rootn(-0.f, 8)));

    // rootn(x, n) -> NaN for x < 0 and even n
    _RS_ASSERT(isnan(rootn(-10000.f, -4)));
    _RS_ASSERT(isnan(rootn(-10000.f, 4)));

    // rootn(x, n) -> value for x < 0 and odd n
    _RS_ASSERT(!isnan(rootn(-10000.f, -3)));
    _RS_ASSERT(!isnan(rootn(-10000.f, 3)));

    if (failed) {
        rsDebug("test_rootn FAILED", -1);
    }
    else {
        rsDebug("test_rootn PASSED", 0);
    }

    return failed;
}

void math_conformance_test() {
    bool failed = false;
    failed |= test_rootn();

    if (failed) {
        rsDebug("math_conformance_test FAILED", -1);
        rsSendToClientBlocking(RS_MSG_TEST_FAILED);
    }
    else {
        rsDebug("math_conformance_test PASSED", 0);
        rsSendToClientBlocking(RS_MSG_TEST_PASSED);
    }
}