1 // 2 // SPDX-License-Identifier: BSD-3-Clause 3 // Copyright (c) Contributors to the OpenEXR Project. 4 // 5 6 #include <ImfNamespace.h> 7 #include <half.h> 8 #include <math.h> 9 #include <iostream> 10 #include <iomanip> 11 #include <assert.h> 12 13 // 14 // This test uses the code from the program that generate the 15 // expTable.h and logTable.h headers and validates that the generated 16 // values match the values from the headers. 17 // 18 19 using namespace std; 20 21 OPENEXR_IMF_INTERNAL_NAMESPACE_SOURCE_ENTER 22 23 #include "b44ExpLogTable.h" 24 25 OPENEXR_IMF_INTERNAL_NAMESPACE_SOURCE_EXIT 26 27 void testB44ExpLogTable(const string &)28testB44ExpLogTable (const string&) 29 { 30 const int iMax = (1 << 16); 31 32 for (int i = 0; i < iMax; i++) 33 { 34 half h; 35 h.setBits (i); 36 37 if (!h.isFinite()) 38 h = 0; 39 else if (h >= 8 * log (HALF_MAX)) 40 h = HALF_MAX; 41 else 42 h = exp (h / 8); 43 44 assert (OPENEXR_IMF_INTERNAL_NAMESPACE::expTable[i] == h.bits()); 45 } 46 47 for (int i = 0; i < iMax; i++) 48 { 49 half h; 50 h.setBits (i); 51 52 if (!h.isFinite() || h < 0) 53 h = 0; 54 else 55 h = 8 * log (h); 56 57 assert (OPENEXR_IMF_INTERNAL_NAMESPACE::logTable[i] == h.bits()); 58 } 59 } 60