PixelLightAPI
.
|
00001 /*********************************************************\ 00002 * File: Half.h * 00003 * 00004 * Copyright (C) 2002-2011 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 <PLCore/PLCore.h> 00032 #include "PLMath/PLMath.h" 00033 00034 00035 //[-------------------------------------------------------] 00036 //[ Namespace ] 00037 //[-------------------------------------------------------] 00038 namespace PLMath { 00039 00040 00041 //[-------------------------------------------------------] 00042 //[ Classes ] 00043 //[-------------------------------------------------------] 00044 /** 00045 * @brief 00046 * Static helper class for the half data type (16 bit floating point) 00047 * 00048 * @note 00049 * - This class is using information from "Fast Half Float Conversions" (http://www.fox-toolkit.org/ftp/fasthalffloatconversion.pdf) 00050 * written by Jeroen van der Zijp, November 2008 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 inline static 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 inline static 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 inline static 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 inline static 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 inline static 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 inline static 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 inline static 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 * [TODO] 00169 * - Implement 00170 */ 00171 inline static float ToFloat(PLCore::uint16 nHalf); 00172 00173 /** 00174 * @brief 00175 * Converts a given float value into a half value 00176 * 00177 * @param[in] fFloat 00178 * Float value to convert 00179 * 00180 * @return 00181 * The given float value as half 00182 * 00183 * [TODO] 00184 * - Implement 00185 */ 00186 inline static PLCore::uint16 FromFloat(float fFloat); 00187 00188 00189 }; 00190 00191 00192 //[-------------------------------------------------------] 00193 //[ Namespace ] 00194 //[-------------------------------------------------------] 00195 } // PLMath 00196 00197 00198 //[-------------------------------------------------------] 00199 //[ Implementation ] 00200 //[-------------------------------------------------------] 00201 #include "PLMath/Half.inl" 00202 00203 00204 #endif // __PLMATH_HALF_H__
|