• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
deToDouble(deFloat16 x)31 DE_INLINE double	deToDouble	(deFloat16 x)	{ return deFloat16To64(x); }
deToDouble(float x)32 DE_INLINE double	deToDouble	(float x)		{ return x; }
deToDouble(double x)33 DE_INLINE double	deToDouble	(double x)		{ return x; }
34 
35 template <typename T>
deToFloatType(double x)36 inline T deToFloatType(double x)
37 {
38 	return static_cast<T>(x);
39 }
40 
41 template <>
deToFloatType(double x)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.
deIsPositiveZero(deFloat16 x)50 DE_INLINE deBool	deIsPositiveZero	(deFloat16 x)	{ return deHalfIsPositiveZero(x); }
deIsPositiveZero(float x)51 DE_INLINE deBool	deIsPositiveZero	(float x)		{ return deFloatIsPositiveZero(x); }
deIsPositiveZero(double x)52 DE_INLINE deBool	deIsPositiveZero	(double x)		{ return deDoubleIsPositiveZero(x); }
deIsNegativeZero(deFloat16 x)53 DE_INLINE deBool	deIsNegativeZero	(deFloat16 x)	{ return deHalfIsNegativeZero(x); }
deIsNegativeZero(float x)54 DE_INLINE deBool	deIsNegativeZero	(float x)		{ return deFloatIsNegativeZero(x); }
deIsNegativeZero(double x)55 DE_INLINE deBool	deIsNegativeZero	(double x)		{ return deDoubleIsNegativeZero(x); }
deIsIEEENaN(deFloat16 x)56 DE_INLINE deBool	deIsIEEENaN			(deFloat16 x)	{ return deHalfIsIEEENaN(x); }
deIsIEEENaN(float x)57 DE_INLINE deBool	deIsIEEENaN			(float x)		{ return deFloatIsIEEENaN(x); }
deIsIEEENaN(double x)58 DE_INLINE deBool	deIsIEEENaN			(double x)		{ return deDoubleIsIEEENaN(x); }
deIsSignalingNaN(deFloat16 x)59 DE_INLINE deBool	deIsSignalingNaN	(deFloat16 x)	{ return deHalfIsSignalingNaN(x); }
deIsSignalingNaN(float x)60 DE_INLINE deBool	deIsSignalingNaN	(float x)		{ return deFloatIsSignalingNaN(x); }
deIsSignalingNaN(double x)61 DE_INLINE deBool	deIsSignalingNaN	(double x)		{ return deDoubleIsSignalingNaN(x); }
deIsQuietNaN(deFloat16 x)62 DE_INLINE deBool	deIsQuietNaN		(deFloat16 x)	{ return deHalfIsQuietNaN(x); }
deIsQuietNaN(float x)63 DE_INLINE deBool	deIsQuietNaN		(float x)		{ return deFloatIsQuietNaN(x); }
deIsQuietNaN(double x)64 DE_INLINE deBool	deIsQuietNaN		(double x)		{ return deDoubleIsQuietNaN(x); }
65 
66 template<typename T>
deQuietNaN()67 inline T deQuietNaN()
68 {
69 	return std::numeric_limits<T>::quiet_NaN();
70 }
71 
72 template<>
deQuietNaN()73 inline deFloat16 deQuietNaN<deFloat16>()
74 {
75 	return deFloat16QuietNaN;
76 }
77 
78 template<typename T>
deSignalingNaN()79 inline T deSignalingNaN()
80 {
81 	return std::numeric_limits<T>::signaling_NaN();
82 }
83 
84 template<>
deSignalingNaN()85 inline deFloat16 deSignalingNaN<deFloat16>()
86 {
87 	return deFloat16SignalingNaN;
88 }
89 
90 #endif // _DEMATH_HPP
91