00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #ifndef FXHALF_H
00022 #define FXHALF_H
00023
00024
00025
00026 #define HALF_MIN 5.9604644775391E-08 // Smallest half number
00027 #define HALF_MAX 65504.0 // Largest half number
00028 #define HALF_EPSILON 0.00097656 // Smallest number where (1+e) != 1
00029
00030
00031 namespace FX {
00032
00033
00035 class FXAPI FXhalf {
00036 private:
00037 FXushort v;
00038 private:
00039 static const FXushort fhb[512];
00040 static const FXuchar fhs[512];
00041 static const FXuint hfm[2048];
00042 static const FXuint hfe[64];
00043 static const FXushort hfw[64];
00044 public:
00045 FXhalf(){}
00046
00047
00048 FXhalf(const FXhalf& h):v(h.v){}
00049
00050
00051 FXhalf(FXfloat f){ union { FXuint u; FXfloat f; } r; r.f=f; v=fhb[(r.u>>23)&0x1ff]+((r.u&0x007fffff)>>fhs[(r.u>>23)&0x1ff]); }
00052
00053
00054 operator FXfloat() const { union { FXuint u; FXfloat f; } r; r.u=hfm[hfw[v>>10]+(v&0x3ff)]+hfe[v>>10]; return r.f; }
00055
00056
00057 FXbool operator!() const { return v==0; }
00058
00059
00060 FXhalf operator+() const { return *this; }
00061 FXhalf operator-() const { FXhalf h; h.v=v^0x8000; return h; }
00062
00063
00064 FXbool operator==(FXhalf h) const { return v==h.v; }
00065 FXbool operator!=(FXhalf h) const { return v!=h.v; }
00066
00067
00068 FXhalf& operator=(FXhalf h){ v=h.v; return *this; }
00069 FXhalf& operator=(FXfloat f){ *this=FXhalf(f); return *this; }
00070
00071
00072 FXhalf& operator+=(FXhalf h){ *this=FXhalf(FXfloat(*this)+FXfloat(h)); return *this; }
00073 FXhalf& operator+=(FXfloat f){ *this=FXhalf(FXfloat(*this)+f); return *this; }
00074
00075 FXhalf& operator-=(FXhalf h){ *this=FXhalf(FXfloat(*this)-FXfloat(h)); return *this; }
00076 FXhalf& operator-=(FXfloat f){ *this=FXhalf(FXfloat(*this)-f); return *this; }
00077
00078 FXhalf& operator*=(FXhalf h){ *this=FXhalf(FXfloat(*this)*FXfloat(h)); return *this; }
00079 FXhalf& operator*=(FXfloat f){ *this=FXhalf(FXfloat(*this)*f); return *this; }
00080
00081 FXhalf& operator/=(FXhalf h){ *this=FXhalf(FXfloat(*this)/FXfloat(h)); return *this; }
00082 FXhalf& operator/=(FXfloat f){ *this=FXhalf(FXfloat(*this)/f); return *this; }
00083 };
00084
00085
00086 }
00087
00088 #endif