PixelLightAPI
.
|
00001 /*********************************************************\ 00002 * File: Half.h * 00003 * 00004 * Copyright (C) 2002-2012 The PixelLight Team (http://www.pixellight.org/) 00005 * 00006 * This file is part of PixelLight. 00007 * 00008 * PixelLight is free software: you can redistribute it and/or modify 00009 * it under the terms of the GNU Lesser General Public License as published by 00010 * the Free Software Foundation, either version 3 of the License, or 00011 * (at your option) any later version. 00012 * 00013 * PixelLight is distributed in the hope that it will be useful, 00014 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00016 * GNU Lesser General Public License for more details. 00017 * 00018 * You should have received a copy of the GNU Lesser General Public License 00019 * along with PixelLight. If not, see <http://www.gnu.org/licenses/>. 00020 \*********************************************************/ 00021 00022 00023 #ifndef __PLMATH_HALF_H__ 00024 #define __PLMATH_HALF_H__ 00025 #pragma once 00026 00027 00028 //[-------------------------------------------------------] 00029 //[ Includes ] 00030 //[-------------------------------------------------------] 00031 #include "PLMath/PLMath.h" 00032 00033 00034 //[-------------------------------------------------------] 00035 //[ Namespace ] 00036 //[-------------------------------------------------------] 00037 namespace PLMath { 00038 00039 00040 //[-------------------------------------------------------] 00041 //[ Classes ] 00042 //[-------------------------------------------------------] 00043 /** 00044 * @brief 00045 * Static helper class for the half data type (16 bit floating point) 00046 * 00047 * @note 00048 * - This class is using information from "Fast Half Float Conversions" (ftp://ftp.fox-toolkit.org/pub/fasthalffloatconversion.pdf) 00049 * written by Jeroen van der Zijp, November 2008 (Revised September 2010) 00050 * - OpenEXR IlmBase 1.0.2 (Modified BSD License) 00051 */ 00052 class Half { 00053 00054 00055 //[-------------------------------------------------------] 00056 //[ Public static data ] 00057 //[-------------------------------------------------------] 00058 public: 00059 // Some half numbers 00060 static PLMATH_API const PLCore::uint16 Zero; /**< Representation of 0.0 */ 00061 static PLMATH_API const PLCore::uint16 One; /**< Representation of 1.0 */ 00062 00063 // Important values 00064 static PLMATH_API const float SmallestPositive; /**< Smallest positive half (5.96046448e-08f) */ 00065 static PLMATH_API const float SmallestPositiveNormalized; /**< Smallest positive normalized half (6.10351562e-05f) */ 00066 static PLMATH_API const float LargestPositive; /**< Largest positive half (65504.0f) */ 00067 static PLMATH_API const float Epsilon; /**< Smallest positive epsilon for which 1+e!=1 (0.00097656f) */ 00068 00069 00070 //[-------------------------------------------------------] 00071 //[ Public functions ] 00072 //[-------------------------------------------------------] 00073 public: 00074 /** 00075 * @brief 00076 * Returns whether or not the given half value is zero 00077 * 00078 * @param[in] nHalf 00079 * Half value to check 00080 * 00081 * @return 00082 * 'true' if the given half value is zero, else 'false' 00083 */ 00084 static inline bool IsZero(PLCore::uint16 nHalf); 00085 00086 /** 00087 * @brief 00088 * Returns whether or not the given half value is negative 00089 * 00090 * @param[in] nHalf 00091 * Half value to check 00092 * 00093 * @return 00094 * 'true' if the given half value is negative, else 'false' 00095 */ 00096 static inline bool IsNegative(PLCore::uint16 nHalf); 00097 00098 /** 00099 * @brief 00100 * Returns whether or not the given half value is not a number (NAN) 00101 * 00102 * @param[in] nHalf 00103 * Half value to check 00104 * 00105 * @return 00106 * 'true' if the given half value is not a number, else 'false' 00107 */ 00108 static inline bool IsNotANumber(PLCore::uint16 nHalf); 00109 00110 /** 00111 * @brief 00112 * Returns whether or not the given half value is finite 00113 * 00114 * @param[in] nHalf 00115 * Half value to check 00116 * 00117 * @return 00118 * 'true' if the given half value is finite, else 'false' 00119 */ 00120 static inline bool IsFinite(PLCore::uint16 nHalf); 00121 00122 /** 00123 * @brief 00124 * Returns whether or not the given half value is infinity 00125 * 00126 * @param[in] nHalf 00127 * Half value to check 00128 * 00129 * @return 00130 * 'true' if the given half value is infinity, else 'false' 00131 */ 00132 static inline bool IsInfinity(PLCore::uint16 nHalf); 00133 00134 /** 00135 * @brief 00136 * Returns whether or not the given half value is normalized 00137 * 00138 * @param[in] nHalf 00139 * Half value to check 00140 * 00141 * @return 00142 * 'true' if the given half value is normalized, else 'false' 00143 */ 00144 static inline bool IsNormalized(PLCore::uint16 nHalf); 00145 00146 /** 00147 * @brief 00148 * Returns whether or not the given half value is de-normalized 00149 * 00150 * @param[in] nHalf 00151 * Half value to check 00152 * 00153 * @return 00154 * 'true' if the given half value is de-normalized, else 'false' 00155 */ 00156 static inline bool IsDenormalized(PLCore::uint16 nHalf); 00157 00158 /** 00159 * @brief 00160 * Converts a given half value into a float value 00161 * 00162 * @param[in] nHalf 00163 * Half value to convert 00164 * 00165 * @return 00166 * The given half value as float 00167 */ 00168 static PLMATH_API float ToFloat(PLCore::uint16 nHalf); 00169 00170 /** 00171 * @brief 00172 * Converts a given float value into a half value 00173 * 00174 * @param[in] fFloat 00175 * Float value to convert 00176 * 00177 * @return 00178 * The given float value as half 00179 */ 00180 static PLMATH_API PLCore::uint16 FromFloat(float fFloat); 00181 00182 00183 }; 00184 00185 00186 //[-------------------------------------------------------] 00187 //[ Namespace ] 00188 //[-------------------------------------------------------] 00189 } // PLMath 00190 00191 00192 //[-------------------------------------------------------] 00193 //[ Implementation ] 00194 //[-------------------------------------------------------] 00195 #include "PLMath/Half.inl" 00196 00197 00198 #endif // __PLMATH_HALF_H__
|