CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
Macros | Enumerations | Functions
IceFPU.h File Reference

Go to the source code of this file.

Macros

#define AIR(x)   (IR(x) & 0x7fffffff)
 Absolute integer representation of a floating-point value. More...
 
#define CHECK_VALID_FLOAT(x)   ASSERT(IsValidFloat(x));
 
#define FR(x)   ((float&)(x))
 Floating-point representation of an integer value. More...
 
#define IR(x)   ((udword&)(x))
 Integer representation of a floating-point value. More...
 
#define IS_NEGATIVE_FLOAT(x)   (IR(x) & 0x80000000)
 
#define SIGN_BITMASK   0x80000000
 
#define SIR(x)   ((sdword&)(x))
 Signed integer representation of a floating-point value. More...
 

Enumerations

enum  FPUMode { FPU_FLOOR = 0, FPU_CEIL = 1, FPU_BEST = 2, FPU_FORCE_DWORD = 0x7fffffff }
 

Functions

inline_ float ComputeFloatEpsilon ()
 This function computes the slowest possible floating-point value (you can also directly use FLT_EPSILON) More...
 
inline_ int ConvertToSortable (float f)
 
inline_ float FastFabs (float x)
 
inline_ float fepsilon (float f)
 Returns the float ranged espilon value. More...
 
inline_ float frsqrt (float f)
 Computes 1.0f / sqrtf(x). More...
 
inline_ float fsat (float f)
 Saturates positive to zero. More...
 
inline_ float fsqrt (float f)
 TO BE DOCUMENTED. More...
 
inline_ float InvSqrt (const float &x)
 Computes 1.0f / sqrtf(x). Comes from NVIDIA. More...
 
inline_ bool IsFloatZero (float x, float epsilon=1e-6f)
 
inline_ bool IsIndeterminate (float value)
 
inline_ bool IsMinusInf (float value)
 
inline_ bool IsNAN (float value)
 Is the float valid ? More...
 
inline_ bool IsPlusInf (float value)
 
inline_ bool IsValidFloat (float value)
 
inline_ float RSqrt (float number)
 

Detailed Description

Contains FPU related code.

Author
Pierre Terdiman
Date
April, 4, 2000

Definition in file IceFPU.h.

Macro Definition Documentation

#define AIR (   x)    (IR(x) & 0x7fffffff)

Absolute integer representation of a floating-point value.

Definition at line 24 of file IceFPU.h.

#define CHECK_VALID_FLOAT (   x)    ASSERT(IsValidFloat(x));

Definition at line 132 of file IceFPU.h.

#define FR (   x)    ((float&)(x))

Floating-point representation of an integer value.

Definition at line 27 of file IceFPU.h.

Referenced by FastFabs().

#define IR (   x)    ((udword&)(x))
#define IS_NEGATIVE_FLOAT (   x)    (IR(x) & 0x80000000)

Integer-based comparison of a floating point value. Don't use it blindly, it can be faster or slower than the FPU comparison, depends on the context.

Definition at line 31 of file IceFPU.h.

#define SIGN_BITMASK   0x80000000

Definition at line 15 of file IceFPU.h.

#define SIR (   x)    ((sdword&)(x))

Signed integer representation of a floating-point value.

Definition at line 21 of file IceFPU.h.

Enumeration Type Documentation

enum FPUMode
Enumerator
FPU_FLOOR 
FPU_CEIL 
FPU_BEST 
FPU_FORCE_DWORD 

Definition at line 249 of file IceFPU.h.

249  {
250  FPU_FLOOR = 0,
251  FPU_CEIL = 1,
252  FPU_BEST = 2,
253 
254  FPU_FORCE_DWORD = 0x7fffffff
255 };

Function Documentation

inline_ float ComputeFloatEpsilon ( )

This function computes the slowest possible floating-point value (you can also directly use FLT_EPSILON)

Definition at line 166 of file IceFPU.h.

References validate-o2o-wbm::f.

166  {
167  float f = 1.0f;
168  ((udword&)f) ^= 1;
169  return f - 1.0f; // You can check it's the same as FLT_EPSILON
170 }
unsigned int udword
sizeof(udword) must be 4
Definition: IceTypes.h:52
inline_ int ConvertToSortable ( float  f)

Definition at line 240 of file IceFPU.h.

240  {
241  int& Fi = (int&)f;
242  int Fmask = (Fi >> 31);
243  Fi ^= Fmask;
244  Fmask &= ~(1 << 31);
245  Fi -= Fmask;
246  return Fi;
247 }
inline_ float FastFabs ( float  x)

Fast fabs for floating-point values. It just clears the sign bit. Don't use it blindy, it can be faster or slower than the FPU comparison, depends on the context.

Definition at line 35 of file IceFPU.h.

References FR, and IR.

35  {
36  udword FloatBits = IR(x) & 0x7fffffff;
37  return FR(FloatBits);
38 }
#define IR(x)
Integer representation of a floating-point value.
Definition: IceFPU.h:18
#define FR(x)
Floating-point representation of an integer value.
Definition: IceFPU.h:27
unsigned int udword
sizeof(udword) must be 4
Definition: IceTypes.h:52
float x
inline_ float fepsilon ( float  f)

Returns the float ranged espilon value.

Definition at line 106 of file IceFPU.h.

References a, and b.

106  {
107  udword b = (udword&)f & 0xff800000;
108  udword a = b | 0x00000001;
109  (float&)a -= (float&)b;
110  // Result
111  return (float&)a;
112 }
unsigned int udword
sizeof(udword) must be 4
Definition: IceTypes.h:52
double b
Definition: hdecay.h:118
double a
Definition: hdecay.h:119
inline_ float frsqrt ( float  f)

Computes 1.0f / sqrtf(x).

Definition at line 63 of file IceFPU.h.

References x, and detailsBasic3DVector::y.

63  {
64  float x = f * 0.5f;
65  udword y = 0x5f3759df - ((udword&)f >> 1);
66  // Iteration...
67  (float&)y = (float&)y * (1.5f - (x * (float&)y * (float&)y));
68  // Result
69  return (float&)y;
70 }
unsigned int udword
sizeof(udword) must be 4
Definition: IceTypes.h:52
float x
inline_ float fsat ( float  f)

Saturates positive to zero.

Definition at line 57 of file IceFPU.h.

References detailsBasic3DVector::y.

57  {
58  udword y = (udword&)f & ~((sdword&)f >> 31);
59  return (float&)y;
60 }
signed int sdword
sizeof(sdword) must be 4
Definition: IceTypes.h:51
unsigned int udword
sizeof(udword) must be 4
Definition: IceTypes.h:52
inline_ float fsqrt ( float  f)

TO BE DOCUMENTED.

Definition at line 97 of file IceFPU.h.

References detailsBasic3DVector::y.

97  {
98  udword y = (((sdword&)f - 0x3f800000) >> 1) + 0x3f800000;
99  // Iteration...?
100  // (float&)y = (3.0f - ((float&)y * (float&)y) / f) * (float&)y * 0.5f;
101  // Result
102  return (float&)y;
103 }
signed int sdword
sizeof(sdword) must be 4
Definition: IceTypes.h:51
unsigned int udword
sizeof(udword) must be 4
Definition: IceTypes.h:52
inline_ float InvSqrt ( const float &  x)

Computes 1.0f / sqrtf(x). Comes from NVIDIA.

Definition at line 73 of file IceFPU.h.

References IEEE_1_0, createJobs::tmp, and detailsBasic3DVector::y.

73  {
74  udword tmp = (udword(IEEE_1_0 << 1) + IEEE_1_0 - *(udword*)&x) >> 1;
75  float y = *(float*)&tmp;
76  return y * (1.47f - 0.47f * x * y * y);
77 }
const udword IEEE_1_0
integer representation of 1.0
Definition: IceTypes.h:81
unsigned int udword
sizeof(udword) must be 4
Definition: IceTypes.h:52
float x
tmp
align.sh
Definition: createJobs.py:716
inline_ bool IsFloatZero ( float  x,
float  epsilon = 1e-6f 
)

Definition at line 172 of file IceFPU.h.

References geometryDiff::epsilon.

172 { return x * x < epsilon; }
float x
inline_ bool IsIndeterminate ( float  value)

Definition at line 116 of file IceFPU.h.

References IR.

Referenced by IsValidFloat().

116 { return IR(value) == 0xffc00000; }
#define IR(x)
Integer representation of a floating-point value.
Definition: IceFPU.h:18
inline_ bool IsMinusInf ( float  value)

Definition at line 118 of file IceFPU.h.

References IR.

Referenced by IsValidFloat().

118 { return IR(value) == 0xff800000; }
#define IR(x)
Integer representation of a floating-point value.
Definition: IceFPU.h:18
inline_ bool IsNAN ( float  value)

Is the float valid ?

Definition at line 115 of file IceFPU.h.

References IR.

Referenced by IsValidFloat().

115 { return (IR(value) & 0x7f800000) == 0x7f800000; }
#define IR(x)
Integer representation of a floating-point value.
Definition: IceFPU.h:18
inline_ bool IsPlusInf ( float  value)

Definition at line 117 of file IceFPU.h.

References IR.

Referenced by IsValidFloat().

117 { return IR(value) == 0x7f800000; }
#define IR(x)
Integer representation of a floating-point value.
Definition: IceFPU.h:18
inline_ bool IsValidFloat ( float  value)

Definition at line 120 of file IceFPU.h.

References IsIndeterminate(), IsMinusInf(), IsNAN(), and IsPlusInf().

120  {
121  if (IsNAN(value))
122  return false;
123  if (IsIndeterminate(value))
124  return false;
125  if (IsPlusInf(value))
126  return false;
127  if (IsMinusInf(value))
128  return false;
129  return true;
130 }
inline_ bool IsMinusInf(float value)
Definition: IceFPU.h:118
inline_ bool IsNAN(float value)
Is the float valid ?
Definition: IceFPU.h:115
inline_ bool IsIndeterminate(float value)
Definition: IceFPU.h:116
inline_ bool IsPlusInf(float value)
Definition: IceFPU.h:117
inline_ float RSqrt ( float  number)

Computes 1.0f / sqrtf(x). Comes from Quake3. Looks like the first one I had above. See http://www.magic-software.com/3DGEDInvSqrt.html

Definition at line 81 of file IceFPU.h.

References mps_fire::i, contentValuesFiles::number, and detailsBasic3DVector::y.

81  {
82  long i;
83  float x2, y;
84  const float threehalfs = 1.5f;
85 
86  x2 = number * 0.5f;
87  y = number;
88  i = *(long*)&y;
89  i = 0x5f3759df - (i >> 1);
90  y = *(float*)&i;
91  y = y * (threehalfs - (x2 * y * y));
92 
93  return y;
94 }