Merge pull request #276 from Ella-0/master
[platform/upstream/VK-GL-CTS.git] / framework / delibs / decpp / deMath.hpp
1 #ifndef _DEMATH_HPP
2 #define _DEMATH_HPP
3 /*-------------------------------------------------------------------------
4  * drawElements Base Portability Library
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 Basic mathematical operations.
24  *//*--------------------------------------------------------------------*/
25
26 #include "deFloat16.h"
27 #include "deMath.h"
28
29 #include <limits>
30
31 DE_INLINE double        deToDouble      (deFloat16 x)   { return deFloat16To64(x); }
32 DE_INLINE double        deToDouble      (float x)               { return x; };
33 DE_INLINE double        deToDouble      (double x)              { return x; };
34
35 template <typename T>
36 inline T deToFloatType(double x)
37 {
38         return static_cast<T>(x);
39 }
40
41 template <>
42 inline deFloat16 deToFloatType<deFloat16>(double x)
43 {
44         return deFloat64To16(x);
45 }
46
47 // These helpers make the C helpers usable from templates.  Because some of
48 // these deal with signaling NaN, it's important that no implicit float
49 // conversion operations happen.
50 DE_INLINE deBool        deIsPositiveZero        (deFloat16 x)   { return deHalfIsPositiveZero(x); };
51 DE_INLINE deBool        deIsPositiveZero        (float x)               { return deFloatIsPositiveZero(x); };
52 DE_INLINE deBool        deIsPositiveZero        (double x)              { return deDoubleIsPositiveZero(x); };
53 DE_INLINE deBool        deIsNegativeZero        (deFloat16 x)   { return deHalfIsNegativeZero(x); };
54 DE_INLINE deBool        deIsNegativeZero        (float x)               { return deFloatIsNegativeZero(x); };
55 DE_INLINE deBool        deIsNegativeZero        (double x)              { return deDoubleIsNegativeZero(x); };
56 DE_INLINE deBool        deIsIEEENaN                     (deFloat16 x)   { return deHalfIsIEEENaN(x); };
57 DE_INLINE deBool        deIsIEEENaN                     (float x)               { return deFloatIsIEEENaN(x); };
58 DE_INLINE deBool        deIsIEEENaN                     (double x)              { return deDoubleIsIEEENaN(x); };
59 DE_INLINE deBool        deIsSignalingNaN        (deFloat16 x)   { return deHalfIsSignalingNaN(x); };
60 DE_INLINE deBool        deIsSignalingNaN        (float x)               { return deFloatIsSignalingNaN(x); };
61 DE_INLINE deBool        deIsSignalingNaN        (double x)              { return deDoubleIsSignalingNaN(x); };
62 DE_INLINE deBool        deIsQuietNaN            (deFloat16 x)   { return deHalfIsQuietNaN(x); };
63 DE_INLINE deBool        deIsQuietNaN            (float x)               { return deFloatIsQuietNaN(x); };
64 DE_INLINE deBool        deIsQuietNaN            (double x)              { return deDoubleIsQuietNaN(x); };
65
66 template<typename T>
67 inline T deQuietNaN()
68 {
69         return std::numeric_limits<T>::quiet_NaN();
70 }
71
72 template<>
73 inline deFloat16 deQuietNaN<deFloat16>()
74 {
75         return deFloat16QuietNaN;
76 }
77
78 template<typename T>
79 inline T deSignalingNaN()
80 {
81         return std::numeric_limits<T>::signaling_NaN();
82 }
83
84 template<>
85 inline deFloat16 deSignalingNaN<deFloat16>()
86 {
87         return deFloat16SignalingNaN;
88 }
89
90 #endif // _DEMATH_HPP