| 1 |
// |
| 2 |
// SPDX-License-Identifier: BSD-3-Clause |
| 3 |
// Copyright Contributors to the OpenEXR Project. |
| 4 |
// |
| 5 |
|
| 6 |
#ifdef NDEBUG |
| 7 |
# undef NDEBUG |
| 8 |
#endif |
| 9 |
|
| 10 |
#include "halfFunction.h" |
| 11 |
#include <assert.h> |
| 12 |
#include <iostream> |
| 13 |
#include "testFunction.h" |
| 14 |
|
| 15 |
using namespace std; |
| 16 |
|
| 17 |
namespace |
| 18 |
{ |
| 19 |
|
| 20 |
float |
| 21 |
divideByTwo (float x) |
| 22 |
{ |
| 23 |
return x / 2; |
| 24 |
} |
| 25 |
|
| 26 |
struct timesN |
| 27 |
{ |
| 28 |
timesN (float n) : n (n) {} |
| 29 |
float operator() (float x) { return x * n; } |
| 30 |
float n; |
| 31 |
}; |
| 32 |
|
| 33 |
} // namespace |
| 34 |
|
| 35 |
void |
| 36 |
testFunction() |
| 37 |
{ |
| 38 |
cout << "halfFunction<T>\n"; |
| 39 |
|
| 40 |
halfFunction<float> d2 (divideByTwo); |
| 41 |
|
| 42 |
assert (d2 (0) == 0); |
| 43 |
assert (d2 (2) == 1); |
| 44 |
assert (d2 (-2) == -1); |
| 45 |
assert (d2 (HALF_MAX) == HALF_MAX / 2); |
| 46 |
assert (d2 (-HALF_MAX) == -HALF_MAX / 2); |
| 47 |
assert (d2 (half::posInf()) == 0); |
| 48 |
assert (d2 (half::negInf()) == 0); |
| 49 |
assert (d2 (half::qNan()) == 0); |
| 50 |
|
| 51 |
halfFunction<half> t5 (timesN (5), // function |
| 52 |
0, |
| 53 |
HALF_MAX / 8, // domain |
| 54 |
-1, // default value |
| 55 |
half::posInf(), // posInfValue |
| 56 |
half::negInf(), // negInfValue |
| 57 |
half::qNan()); // nanValue |
| 58 |
|
| 59 |
assert (t5 (0) == 0); |
| 60 |
assert (t5 (2) == 10); |
| 61 |
assert (t5 (-2) == -1); |
| 62 |
assert (t5 (HALF_MAX) == -1); |
| 63 |
assert (t5 (-HALF_MAX) == -1); |
| 64 |
|
| 65 |
assert (t5 (half::posInf()).isInfinity()); |
| 66 |
assert (!t5 (half::posInf()).isNegative()); |
| 67 |
|
| 68 |
assert (t5 (half::negInf()).isInfinity()); |
| 69 |
assert (t5 (half::negInf()).isNegative()); |
| 70 |
|
| 71 |
assert (t5 (half::qNan()).isNan()); |
| 72 |
|
| 73 |
cout << "ok\n\n" << flush; |
| 74 |
} |