1*35238bceSAndroid Build Coastguard Worker #ifndef _DEMATH_HPP 2*35238bceSAndroid Build Coastguard Worker #define _DEMATH_HPP 3*35238bceSAndroid Build Coastguard Worker /*------------------------------------------------------------------------- 4*35238bceSAndroid Build Coastguard Worker * drawElements Base Portability Library 5*35238bceSAndroid Build Coastguard Worker * ------------------------------------- 6*35238bceSAndroid Build Coastguard Worker * 7*35238bceSAndroid Build Coastguard Worker * Copyright 2014 The Android Open Source Project 8*35238bceSAndroid Build Coastguard Worker * 9*35238bceSAndroid Build Coastguard Worker * Licensed under the Apache License, Version 2.0 (the "License"); 10*35238bceSAndroid Build Coastguard Worker * you may not use this file except in compliance with the License. 11*35238bceSAndroid Build Coastguard Worker * You may obtain a copy of the License at 12*35238bceSAndroid Build Coastguard Worker * 13*35238bceSAndroid Build Coastguard Worker * http://www.apache.org/licenses/LICENSE-2.0 14*35238bceSAndroid Build Coastguard Worker * 15*35238bceSAndroid Build Coastguard Worker * Unless required by applicable law or agreed to in writing, software 16*35238bceSAndroid Build Coastguard Worker * distributed under the License is distributed on an "AS IS" BASIS, 17*35238bceSAndroid Build Coastguard Worker * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 18*35238bceSAndroid Build Coastguard Worker * See the License for the specific language governing permissions and 19*35238bceSAndroid Build Coastguard Worker * limitations under the License. 20*35238bceSAndroid Build Coastguard Worker * 21*35238bceSAndroid Build Coastguard Worker *//*! 22*35238bceSAndroid Build Coastguard Worker * \file 23*35238bceSAndroid Build Coastguard Worker * \brief Basic mathematical operations. 24*35238bceSAndroid Build Coastguard Worker *//*--------------------------------------------------------------------*/ 25*35238bceSAndroid Build Coastguard Worker 26*35238bceSAndroid Build Coastguard Worker #include "deFloat16.h" 27*35238bceSAndroid Build Coastguard Worker #include "deMath.h" 28*35238bceSAndroid Build Coastguard Worker 29*35238bceSAndroid Build Coastguard Worker #include <limits> 30*35238bceSAndroid Build Coastguard Worker deToDouble(deFloat16 x)31*35238bceSAndroid Build Coastguard WorkerDE_INLINE double deToDouble(deFloat16 x) 32*35238bceSAndroid Build Coastguard Worker { 33*35238bceSAndroid Build Coastguard Worker return deFloat16To64(x); 34*35238bceSAndroid Build Coastguard Worker } deToDouble(float x)35*35238bceSAndroid Build Coastguard WorkerDE_INLINE double deToDouble(float x) 36*35238bceSAndroid Build Coastguard Worker { 37*35238bceSAndroid Build Coastguard Worker return x; 38*35238bceSAndroid Build Coastguard Worker } deToDouble(double x)39*35238bceSAndroid Build Coastguard WorkerDE_INLINE double deToDouble(double x) 40*35238bceSAndroid Build Coastguard Worker { 41*35238bceSAndroid Build Coastguard Worker return x; 42*35238bceSAndroid Build Coastguard Worker } 43*35238bceSAndroid Build Coastguard Worker 44*35238bceSAndroid Build Coastguard Worker template <typename T> deToFloatType(double x)45*35238bceSAndroid Build Coastguard Workerinline T deToFloatType(double x) 46*35238bceSAndroid Build Coastguard Worker { 47*35238bceSAndroid Build Coastguard Worker return static_cast<T>(x); 48*35238bceSAndroid Build Coastguard Worker } 49*35238bceSAndroid Build Coastguard Worker 50*35238bceSAndroid Build Coastguard Worker template <> deToFloatType(double x)51*35238bceSAndroid Build Coastguard Workerinline deFloat16 deToFloatType<deFloat16>(double x) 52*35238bceSAndroid Build Coastguard Worker { 53*35238bceSAndroid Build Coastguard Worker return deFloat64To16(x); 54*35238bceSAndroid Build Coastguard Worker } 55*35238bceSAndroid Build Coastguard Worker 56*35238bceSAndroid Build Coastguard Worker // These helpers make the C helpers usable from templates. Because some of 57*35238bceSAndroid Build Coastguard Worker // these deal with signaling NaN, it's important that no implicit float 58*35238bceSAndroid Build Coastguard Worker // conversion operations happen. deIsPositiveZero(deFloat16 x)59*35238bceSAndroid Build Coastguard WorkerDE_INLINE bool deIsPositiveZero(deFloat16 x) 60*35238bceSAndroid Build Coastguard Worker { 61*35238bceSAndroid Build Coastguard Worker return deHalfIsPositiveZero(x); 62*35238bceSAndroid Build Coastguard Worker } deIsPositiveZero(float x)63*35238bceSAndroid Build Coastguard WorkerDE_INLINE bool deIsPositiveZero(float x) 64*35238bceSAndroid Build Coastguard Worker { 65*35238bceSAndroid Build Coastguard Worker return deFloatIsPositiveZero(x); 66*35238bceSAndroid Build Coastguard Worker } deIsPositiveZero(double x)67*35238bceSAndroid Build Coastguard WorkerDE_INLINE bool deIsPositiveZero(double x) 68*35238bceSAndroid Build Coastguard Worker { 69*35238bceSAndroid Build Coastguard Worker return deDoubleIsPositiveZero(x); 70*35238bceSAndroid Build Coastguard Worker } deIsNegativeZero(deFloat16 x)71*35238bceSAndroid Build Coastguard WorkerDE_INLINE bool deIsNegativeZero(deFloat16 x) 72*35238bceSAndroid Build Coastguard Worker { 73*35238bceSAndroid Build Coastguard Worker return deHalfIsNegativeZero(x); 74*35238bceSAndroid Build Coastguard Worker } deIsNegativeZero(float x)75*35238bceSAndroid Build Coastguard WorkerDE_INLINE bool deIsNegativeZero(float x) 76*35238bceSAndroid Build Coastguard Worker { 77*35238bceSAndroid Build Coastguard Worker return deFloatIsNegativeZero(x); 78*35238bceSAndroid Build Coastguard Worker } deIsNegativeZero(double x)79*35238bceSAndroid Build Coastguard WorkerDE_INLINE bool deIsNegativeZero(double x) 80*35238bceSAndroid Build Coastguard Worker { 81*35238bceSAndroid Build Coastguard Worker return deDoubleIsNegativeZero(x); 82*35238bceSAndroid Build Coastguard Worker } deIsIEEENaN(deFloat16 x)83*35238bceSAndroid Build Coastguard WorkerDE_INLINE bool deIsIEEENaN(deFloat16 x) 84*35238bceSAndroid Build Coastguard Worker { 85*35238bceSAndroid Build Coastguard Worker return deHalfIsIEEENaN(x); 86*35238bceSAndroid Build Coastguard Worker } deIsIEEENaN(float x)87*35238bceSAndroid Build Coastguard WorkerDE_INLINE bool deIsIEEENaN(float x) 88*35238bceSAndroid Build Coastguard Worker { 89*35238bceSAndroid Build Coastguard Worker return deFloatIsIEEENaN(x); 90*35238bceSAndroid Build Coastguard Worker } deIsIEEENaN(double x)91*35238bceSAndroid Build Coastguard WorkerDE_INLINE bool deIsIEEENaN(double x) 92*35238bceSAndroid Build Coastguard Worker { 93*35238bceSAndroid Build Coastguard Worker return deDoubleIsIEEENaN(x); 94*35238bceSAndroid Build Coastguard Worker } deIsSignalingNaN(deFloat16 x)95*35238bceSAndroid Build Coastguard WorkerDE_INLINE bool deIsSignalingNaN(deFloat16 x) 96*35238bceSAndroid Build Coastguard Worker { 97*35238bceSAndroid Build Coastguard Worker return deHalfIsSignalingNaN(x); 98*35238bceSAndroid Build Coastguard Worker } deIsSignalingNaN(float x)99*35238bceSAndroid Build Coastguard WorkerDE_INLINE bool deIsSignalingNaN(float x) 100*35238bceSAndroid Build Coastguard Worker { 101*35238bceSAndroid Build Coastguard Worker return deFloatIsSignalingNaN(x); 102*35238bceSAndroid Build Coastguard Worker } deIsSignalingNaN(double x)103*35238bceSAndroid Build Coastguard WorkerDE_INLINE bool deIsSignalingNaN(double x) 104*35238bceSAndroid Build Coastguard Worker { 105*35238bceSAndroid Build Coastguard Worker return deDoubleIsSignalingNaN(x); 106*35238bceSAndroid Build Coastguard Worker } deIsQuietNaN(deFloat16 x)107*35238bceSAndroid Build Coastguard WorkerDE_INLINE bool deIsQuietNaN(deFloat16 x) 108*35238bceSAndroid Build Coastguard Worker { 109*35238bceSAndroid Build Coastguard Worker return deHalfIsQuietNaN(x); 110*35238bceSAndroid Build Coastguard Worker } deIsQuietNaN(float x)111*35238bceSAndroid Build Coastguard WorkerDE_INLINE bool deIsQuietNaN(float x) 112*35238bceSAndroid Build Coastguard Worker { 113*35238bceSAndroid Build Coastguard Worker return deFloatIsQuietNaN(x); 114*35238bceSAndroid Build Coastguard Worker } deIsQuietNaN(double x)115*35238bceSAndroid Build Coastguard WorkerDE_INLINE bool deIsQuietNaN(double x) 116*35238bceSAndroid Build Coastguard Worker { 117*35238bceSAndroid Build Coastguard Worker return deDoubleIsQuietNaN(x); 118*35238bceSAndroid Build Coastguard Worker } 119*35238bceSAndroid Build Coastguard Worker 120*35238bceSAndroid Build Coastguard Worker template <typename T> deQuietNaN()121*35238bceSAndroid Build Coastguard Workerinline T deQuietNaN() 122*35238bceSAndroid Build Coastguard Worker { 123*35238bceSAndroid Build Coastguard Worker return std::numeric_limits<T>::quiet_NaN(); 124*35238bceSAndroid Build Coastguard Worker } 125*35238bceSAndroid Build Coastguard Worker 126*35238bceSAndroid Build Coastguard Worker template <> deQuietNaN()127*35238bceSAndroid Build Coastguard Workerinline deFloat16 deQuietNaN<deFloat16>() 128*35238bceSAndroid Build Coastguard Worker { 129*35238bceSAndroid Build Coastguard Worker return deFloat16QuietNaN; 130*35238bceSAndroid Build Coastguard Worker } 131*35238bceSAndroid Build Coastguard Worker 132*35238bceSAndroid Build Coastguard Worker template <typename T> deSignalingNaN()133*35238bceSAndroid Build Coastguard Workerinline T deSignalingNaN() 134*35238bceSAndroid Build Coastguard Worker { 135*35238bceSAndroid Build Coastguard Worker return std::numeric_limits<T>::signaling_NaN(); 136*35238bceSAndroid Build Coastguard Worker } 137*35238bceSAndroid Build Coastguard Worker 138*35238bceSAndroid Build Coastguard Worker template <> deSignalingNaN()139*35238bceSAndroid Build Coastguard Workerinline deFloat16 deSignalingNaN<deFloat16>() 140*35238bceSAndroid Build Coastguard Worker { 141*35238bceSAndroid Build Coastguard Worker return deFloat16SignalingNaN; 142*35238bceSAndroid Build Coastguard Worker } 143*35238bceSAndroid Build Coastguard Worker 144*35238bceSAndroid Build Coastguard Worker #endif // _DEMATH_HPP 145