resolve merge conflicts of 297d0b5c to deqp-dev
[platform/upstream/VK-GL-CTS.git] / framework / common / tcuFloatFormat.hpp
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
28 #include "tcuInterval.hpp"
29
30 #include <string>
31
32 namespace tcu
33 {
34
35 enum YesNoMaybe
36 {
37         NO,
38         MAYBE,
39         YES
40 };
41
42 class FloatFormat
43 {
44 public:
45
46                                                 FloatFormat     (int            minExp,
47                                                                          int            maxExp,
48                                                                          int            fractionBits,
49                                                                          bool           exactPrecision,
50                                                                          YesNoMaybe     hasSubnormal    = MAYBE,
51                                                                          YesNoMaybe     hasInf                  = MAYBE,
52                                                                          YesNoMaybe     hasNaN                  = MAYBE);
53
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; }
60
61         double                          ulp                             (double x, double count = 1.0) const;
62         Interval                        roundOut                (const Interval& x, bool roundUnderOverflow) const;
63         double                          round                   (double d, bool upward) const;
64         double                          roundOut                (double d, bool upward, bool roundUnderOverflow) const;
65         Interval                        convert                 (const Interval& x) const;
66
67         std::string                     floatToHex              (double x) const;
68         std::string                     intervalToHex   (const Interval& interval) const;
69
70         static FloatFormat      nativeFloat             (void);
71         static FloatFormat      nativeDouble    (void);
72
73 private:
74         int                                     exponentShift   (int exp) const;
75         Interval                        clampValue              (double d) const;
76
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;
86
87 void            FloatFormat_selfTest    (void);
88
89 } // tcu
90
91 #endif // _TCUFLOATFORMAT_HPP