1 #ifndef _TCUFLOATFORMAT_HPP
2 #define _TCUFLOATFORMAT_HPP
3 /*-------------------------------------------------------------------------
4 * drawElements Quality Program Tester Core
5 * ----------------------------------------
7 * Copyright 2014 The Android Open Source Project
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
13 * http://www.apache.org/licenses/LICENSE-2.0
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.
23 * \brief Adjustable-precision floating point operations.
24 *//*--------------------------------------------------------------------*/
26 #include "tcuDefs.hpp"
27 #include "tcuInterval.hpp"
45 FloatFormat (int minExp,
49 YesNoMaybe hasSubnormal = MAYBE,
50 YesNoMaybe hasInf = MAYBE,
51 YesNoMaybe hasNaN = MAYBE);
52 virtual ~FloatFormat() {}
54 int getMinExp (void) const { return m_minExp; }
55 int getMaxExp (void) const { return m_maxExp; }
56 double getMaxValue (void) const { return m_maxValue; }
57 int getFractionBits (void) const { return m_fractionBits; }
58 YesNoMaybe hasInf (void) const { return m_hasInf; }
59 YesNoMaybe hasSubnormal (void) const { return m_hasSubnormal; }
61 virtual double ulp (double x, double count = 1.0) const;
62 Interval roundOut (const Interval& x, bool roundUnderOverflow) const;
63 virtual double round (double d, bool upward) const;
64 virtual double roundOut (double d, bool upward, bool roundUnderOverflow) const;
65 Interval convert (const Interval& x) const;
67 std::string floatToHex (double x) const;
68 std::string intervalToHex (const Interval& interval) const;
70 static FloatFormat nativeFloat (void);
71 static FloatFormat nativeDouble (void);
74 int exponentShift (int exp) const;
75 Interval clampValue (double d) const;
77 int m_minExp; // Minimum exponent, inclusive
78 int m_maxExp; // Maximum exponent, inclusive
79 int m_fractionBits; // Number of fractional bits in significand
80 YesNoMaybe m_hasSubnormal; // Does the format support denormalized numbers?
81 YesNoMaybe m_hasInf; // Does the format support infinities?
82 YesNoMaybe m_hasNaN; // Does the format support NaNs?
83 bool m_exactPrecision; // Are larger precisions disallowed?
84 double m_maxValue; // Largest representable finite value.
85 } DE_WARN_UNUSED_TYPE;
87 class NormalizedFormat : public FloatFormat
90 NormalizedFormat (int fractionBits);
91 ~NormalizedFormat () {}
93 double ulp (double x, double count = 1.0) const override;
94 double round (double d, bool upward) const override;
95 double roundOut (double d, bool upward, bool roundUnderOverflow) const override;
97 } DE_WARN_UNUSED_TYPE;
99 void FloatFormat_selfTest (void);
103 #endif // _TCUFLOATFORMAT_HPP