| 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 <half.h> |
| 11 |
#include <assert.h> |
| 12 |
#include <iostream> |
| 13 |
#include "testArithmetic.h" |
| 14 |
|
| 15 |
using namespace std; |
| 16 |
|
| 17 |
void |
| 18 |
testArithmetic() |
| 19 |
{ |
| 20 |
cout << "basic arithmetic operations:\n"; |
| 21 |
|
| 22 |
float f1 (1); |
| 23 |
float f2 (2); |
| 24 |
half h1 (3); |
| 25 |
half h2 (4); |
| 26 |
|
| 27 |
cout << "f1 = " << f1 |
| 28 |
<< ", " |
| 29 |
"f2 = " |
| 30 |
<< f2 |
| 31 |
<< ", " |
| 32 |
"h1 = " |
| 33 |
<< h1 |
| 34 |
<< ", " |
| 35 |
"h2 = " |
| 36 |
<< h2 << endl; |
| 37 |
|
| 38 |
h1 = f1 + f2; |
| 39 |
assert (h1 == 3); |
| 40 |
|
| 41 |
cout << "h1 = f1 + f2: " << h1 << endl; |
| 42 |
|
| 43 |
h2 += f1; |
| 44 |
assert (h2 == 5); |
| 45 |
|
| 46 |
cout << "h2 += f1: " << h2 << endl; |
| 47 |
|
| 48 |
h2 = h1 + h2; |
| 49 |
assert (h2 == 8); |
| 50 |
|
| 51 |
cout << "h2 = h1 + h2: " << h2 << endl; |
| 52 |
|
| 53 |
h2 += h1; |
| 54 |
assert (h2 == 11); |
| 55 |
|
| 56 |
cout << "h2 += h1: " << h2 << endl; |
| 57 |
|
| 58 |
h1 = h2; |
| 59 |
assert (h1 == 11); |
| 60 |
|
| 61 |
cout << "h1 = h2: " << h1 << endl; |
| 62 |
|
| 63 |
h2 = -h1; |
| 64 |
assert (h2 == -11); |
| 65 |
|
| 66 |
cout << "h2 = -h1: " << h2 << endl; |
| 67 |
|
| 68 |
cout << "ok\n\n" << flush; |
| 69 |
} |