1 #ifndef _TCUFLOATFORMAT_HPP 2 #define _TCUFLOATFORMAT_HPP 3 /*------------------------------------------------------------------------- 4 * drawElements Quality Program Tester Core 5 * ---------------------------------------- 6 * 7 * Copyright 2014 The Android Open Source Project 8 * 9 * Licensed under the Apache License, Version 2.0 (the "License"); 10 * you may not use this file except in compliance with the License. 11 * You may obtain a copy of the License at 12 * 13 * http://www.apache.org/licenses/LICENSE-2.0 14 * 15 * Unless required by applicable law or agreed to in writing, software 16 * distributed under the License is distributed on an "AS IS" BASIS, 17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 18 * See the License for the specific language governing permissions and 19 * limitations under the License. 20 * 21 *//*! 22 * \file 23 * \brief Adjustable-precision floating point operations. 24 *//*--------------------------------------------------------------------*/ 25 26 #include "tcuDefs.hpp" 27 #include "tcuInterval.hpp" 28 29 #include <string> 30 31 namespace tcu 32 { 33 34 enum YesNoMaybe 35 { 36 NO, 37 MAYBE, 38 YES 39 }; 40 41 class FloatFormat 42 { 43 public: 44 45 FloatFormat (int minExp, 46 int maxExp, 47 int fractionBits, 48 bool exactPrecision, 49 YesNoMaybe hasSubnormal = MAYBE, 50 YesNoMaybe hasInf = MAYBE, 51 YesNoMaybe hasNaN = MAYBE); 52 getMinExp(void) const53 int getMinExp (void) const { return m_minExp; } getMaxExp(void) const54 int getMaxExp (void) const { return m_maxExp; } getMaxValue(void) const55 double getMaxValue (void) const { return m_maxValue; } getFractionBits(void) const56 int getFractionBits (void) const { return m_fractionBits; } hasInf(void) const57 YesNoMaybe hasInf (void) const { return m_hasInf; } hasSubnormal(void) const58 YesNoMaybe hasSubnormal (void) const { return m_hasSubnormal; } 59 60 double ulp (double x, double count = 1.0) const; 61 Interval roundOut (const Interval& x, bool roundUnderOverflow) const; 62 double round (double d, bool upward) const; 63 double roundOut (double d, bool upward, bool roundUnderOverflow) const; 64 Interval convert (const Interval& x) const; 65 66 std::string floatToHex (double x) const; 67 std::string intervalToHex (const Interval& interval) const; 68 69 static FloatFormat nativeFloat (void); 70 static FloatFormat nativeDouble (void); 71 72 private: 73 int exponentShift (int exp) const; 74 Interval clampValue (double d) const; 75 76 int m_minExp; // Minimum exponent, inclusive 77 int m_maxExp; // Maximum exponent, inclusive 78 int m_fractionBits; // Number of fractional bits in significand 79 YesNoMaybe m_hasSubnormal; // Does the format support denormalized numbers? 80 YesNoMaybe m_hasInf; // Does the format support infinities? 81 YesNoMaybe m_hasNaN; // Does the format support NaNs? 82 bool m_exactPrecision; // Are larger precisions disallowed? 83 double m_maxValue; // Largest representable finite value. 84 } DE_WARN_UNUSED_TYPE; 85 86 void FloatFormat_selfTest (void); 87 88 } // tcu 89 90 #endif // _TCUFLOATFORMAT_HPP 91