OpenClonk
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros
C4Fixed Class Reference

#include <C4Real.h>

Public Member Functions

 C4Fixed ()
 
 C4Fixed (const C4Fixed &rCpy)
 
C4Fixedoperator= (int32_t x)
 
 operator bool () const
 
bool operator! () const
 
C4Fixedoperator+= (const C4Fixed &fVal2)
 
C4Fixedoperator-= (const C4Fixed &fVal2)
 
C4Fixedoperator*= (const C4Fixed &fVal2)
 
C4Fixedoperator*= (int32_t iVal2)
 
C4Fixedoperator/= (const C4Fixed &fVal2)
 
C4Fixedoperator/= (int32_t iVal2)
 
C4Fixed operator- () const
 
C4Fixed operator+ () const
 
bool operator== (const C4Fixed &fVal2) const
 
bool operator< (const C4Fixed &fVal2) const
 
bool operator> (const C4Fixed &fVal2) const
 
bool operator<= (const C4Fixed &fVal2) const
 
bool operator>= (const C4Fixed &fVal2) const
 
bool operator!= (const C4Fixed &fVal2) const
 
C4Fixedoperator+= (int32_t iVal2)
 
C4Fixedoperator-= (int32_t iVal2)
 
C4Fixed operator+ (const C4Fixed &fVal2) const
 
C4Fixed operator- (const C4Fixed &fVal2) const
 
C4Fixed operator* (const C4Fixed &fVal2) const
 
C4Fixed operator/ (const C4Fixed &fVal2) const
 
C4Fixed operator+ (int32_t iVal2) const
 
C4Fixed operator- (int32_t iVal2) const
 
C4Fixed operator* (int32_t iVal2) const
 
C4Fixed operator/ (int32_t iVal2) const
 
C4Fixed operator+ (float iVal2) const
 
C4Fixed operator- (float iVal2) const
 
C4Fixed operator* (float iVal2) const
 
C4Fixed operator/ (float iVal2) const
 
bool operator== (int32_t iVal2) const
 
bool operator< (int32_t iVal2) const
 
bool operator> (int32_t iVal2) const
 
bool operator<= (int32_t iVal2) const
 
bool operator>= (int32_t iVal2) const
 
bool operator!= (int32_t iVal2) const
 
bool operator== (float iVal2) const
 
bool operator< (float iVal2) const
 
bool operator> (float iVal2) const
 
bool operator<= (float iVal2) const
 
bool operator>= (float iVal2) const
 
bool operator!= (float iVal2) const
 
C4Fixed sin_deg () const
 
C4Fixed cos_deg () const
 

Public Attributes

int32_t val
 

Friends

int fixtoi (const C4Fixed &x)
 
int fixtoi (const C4Fixed &x, int32_t prec)
 
C4Fixed itofix (int32_t x)
 
C4Fixed itofix (int32_t x, int32_t prec)
 
float fixtof (const C4Fixed &x)
 
C4Fixed ftofix (float x)
 
void CompileFunc (C4Fixed &rValue, StdCompiler *pComp)
 

Detailed Description

Definition at line 58 of file C4Real.h.

Constructor & Destructor Documentation

C4Fixed::C4Fixed ( )
inline

Definition at line 77 of file C4Real.h.

Referenced by operator!=(), operator*(), operator+(), operator+=(), operator-(), operator-=(), operator/(), operator<(), operator<=(), operator=(), operator==(), operator>(), and operator>=().

77 { }

Here is the caller graph for this function:

C4Fixed::C4Fixed ( const C4Fixed rCpy)
inline

Definition at line 78 of file C4Real.h.

78 : val(rCpy.val) { }
int32_t val
Definition: C4Real.h:73

Member Function Documentation

C4Fixed C4Fixed::cos_deg ( ) const
inline

Definition at line 233 of file C4Real.h.

References FIXED_FPF, SineTable, and val.

Referenced by Cos().

234  {
235  // adjust angle
236  int32_t v=int32_t((int64_t(val)*100)/FIXED_FPF); if (v<0) v=-v; v%=36000;
237  // get cosine
238  C4Fixed fr;
239  switch (v/9000)
240  {
241  case 0: fr.val=+SineTable[9000-v]; break;
242  case 1: fr.val=-SineTable[v-9000]; break;
243  case 2: fr.val=-SineTable[27000-v]; break;
244  case 3: fr.val=+SineTable[v-27000]; break;
245  }
246  return fr;
247  }
Definition: C4Real.h:58
long SineTable[9001]
#define FIXED_FPF
Definition: C4Real.h:56
int32_t val
Definition: C4Real.h:73

Here is the caller graph for this function:

C4Fixed::operator bool ( ) const
inline

Definition at line 126 of file C4Real.h.

References val.

126 { return !! val; }
int32_t val
Definition: C4Real.h:73
bool C4Fixed::operator! ( ) const
inline

Definition at line 127 of file C4Real.h.

References val.

127 { return ! val; }
int32_t val
Definition: C4Real.h:73
bool C4Fixed::operator!= ( const C4Fixed fVal2) const
inline

Definition at line 182 of file C4Real.h.

References val.

Referenced by operator!=().

182 { return val!=fVal2.val; }
int32_t val
Definition: C4Real.h:73

Here is the caller graph for this function:

bool C4Fixed::operator!= ( int32_t  iVal2) const
inline

Definition at line 208 of file C4Real.h.

References C4Fixed(), and operator!=().

208 { return operator != (C4Fixed(iVal2)); }
C4Fixed()
Definition: C4Real.h:77
bool operator!=(const C4Fixed &fVal2) const
Definition: C4Real.h:182

Here is the call graph for this function:

bool C4Fixed::operator!= ( float  iVal2) const
inline

Definition at line 215 of file C4Real.h.

References C4Fixed(), and operator!=().

215 { return operator != (C4Fixed(iVal2)); }
C4Fixed()
Definition: C4Real.h:77
bool operator!=(const C4Fixed &fVal2) const
Definition: C4Real.h:182

Here is the call graph for this function:

C4Fixed C4Fixed::operator* ( const C4Fixed fVal2) const
inline

Definition at line 190 of file C4Real.h.

References C4Fixed().

190 { return C4Fixed(*this) *= fVal2; }
C4Fixed()
Definition: C4Real.h:77

Here is the call graph for this function:

C4Fixed C4Fixed::operator* ( int32_t  iVal2) const
inline

Definition at line 195 of file C4Real.h.

References C4Fixed().

195 { return C4Fixed(*this) *= iVal2; }
C4Fixed()
Definition: C4Real.h:77

Here is the call graph for this function:

C4Fixed C4Fixed::operator* ( float  iVal2) const
inline

Definition at line 200 of file C4Real.h.

References C4Fixed().

200 { return C4Fixed(*this) *= iVal2; }
C4Fixed()
Definition: C4Real.h:77

Here is the call graph for this function:

C4Fixed& C4Fixed::operator*= ( const C4Fixed fVal2)
inline

Definition at line 140 of file C4Real.h.

References FIXED_FPF, FIXED_SHIFT, and val.

141  {
142 #ifndef FIXED_EMULATE_64BIT
143  val = int32_t( (int64_t(val) * fVal2.val) / FIXED_FPF );
144 #else
145  uint32_t x0 = val & (FIXED_FPF - 1);
146  int32_t x1 = val >> FIXED_SHIFT;
147  uint32_t y0 = fVal2.val & (FIXED_FPF - 1);
148  int32_t y1 = fVal2.val >> FIXED_SHIFT;
149  val = int32_t(x0*y0/FIXED_FPF) + int32_t(x0)*y1 + x1*int32_t(y0) + x1*y1*FIXED_FPF;
150 #endif
151  return *this;
152  }
#define FIXED_FPF
Definition: C4Real.h:56
int32_t val
Definition: C4Real.h:73
#define FIXED_SHIFT
Definition: C4Real.h:54
C4Fixed& C4Fixed::operator*= ( int32_t  iVal2)
inline

Definition at line 153 of file C4Real.h.

154  {
155  val *= iVal2;
156  return *this;
157  }
int32_t val
Definition: C4Real.h:73
C4Fixed C4Fixed::operator+ ( ) const
inline

Definition at line 172 of file C4Real.h.

173  {
174  return *this;
175  }
C4Fixed C4Fixed::operator+ ( const C4Fixed fVal2) const
inline

Definition at line 188 of file C4Real.h.

References C4Fixed().

188 { return C4Fixed(*this) += fVal2; }
C4Fixed()
Definition: C4Real.h:77

Here is the call graph for this function:

C4Fixed C4Fixed::operator+ ( int32_t  iVal2) const
inline

Definition at line 193 of file C4Real.h.

References C4Fixed().

193 { return C4Fixed(*this) += iVal2; }
C4Fixed()
Definition: C4Real.h:77

Here is the call graph for this function:

C4Fixed C4Fixed::operator+ ( float  iVal2) const
inline

Definition at line 198 of file C4Real.h.

References C4Fixed().

198 { return C4Fixed(*this) += iVal2; }
C4Fixed()
Definition: C4Real.h:77

Here is the call graph for this function:

C4Fixed& C4Fixed::operator+= ( const C4Fixed fVal2)
inline

Definition at line 130 of file C4Real.h.

References val.

Referenced by operator+=().

131  {
132  val += fVal2.val;
133  return *this;
134  }
int32_t val
Definition: C4Real.h:73

Here is the caller graph for this function:

C4Fixed& C4Fixed::operator+= ( int32_t  iVal2)
inline

Definition at line 185 of file C4Real.h.

References C4Fixed(), and operator+=().

185 { return operator += (C4Fixed(iVal2)); }
C4Fixed()
Definition: C4Real.h:77
C4Fixed & operator+=(const C4Fixed &fVal2)
Definition: C4Real.h:130

Here is the call graph for this function:

C4Fixed C4Fixed::operator- ( ) const
inline

Definition at line 168 of file C4Real.h.

References val.

169  {
170  C4Fixed fr; fr.val=-val; return fr;
171  }
Definition: C4Real.h:58
int32_t val
Definition: C4Real.h:73
C4Fixed C4Fixed::operator- ( const C4Fixed fVal2) const
inline

Definition at line 189 of file C4Real.h.

References C4Fixed().

189 { return C4Fixed(*this) -= fVal2; }
C4Fixed()
Definition: C4Real.h:77

Here is the call graph for this function:

C4Fixed C4Fixed::operator- ( int32_t  iVal2) const
inline

Definition at line 194 of file C4Real.h.

References C4Fixed().

194 { return C4Fixed(*this) -= iVal2; }
C4Fixed()
Definition: C4Real.h:77

Here is the call graph for this function:

C4Fixed C4Fixed::operator- ( float  iVal2) const
inline

Definition at line 199 of file C4Real.h.

References C4Fixed().

199 { return C4Fixed(*this) -= iVal2; }
C4Fixed()
Definition: C4Real.h:77

Here is the call graph for this function:

C4Fixed& C4Fixed::operator-= ( const C4Fixed fVal2)
inline

Definition at line 135 of file C4Real.h.

References val.

Referenced by operator-=().

136  {
137  val -= fVal2.val;
138  return *this;
139  }
int32_t val
Definition: C4Real.h:73

Here is the caller graph for this function:

C4Fixed& C4Fixed::operator-= ( int32_t  iVal2)
inline

Definition at line 186 of file C4Real.h.

References C4Fixed(), and operator-=().

186 { return operator -= (C4Fixed(iVal2)); }
C4Fixed & operator-=(const C4Fixed &fVal2)
Definition: C4Real.h:135
C4Fixed()
Definition: C4Real.h:77

Here is the call graph for this function:

C4Fixed C4Fixed::operator/ ( const C4Fixed fVal2) const
inline

Definition at line 191 of file C4Real.h.

References C4Fixed().

191 { return C4Fixed(*this) /= fVal2; }
C4Fixed()
Definition: C4Real.h:77

Here is the call graph for this function:

C4Fixed C4Fixed::operator/ ( int32_t  iVal2) const
inline

Definition at line 196 of file C4Real.h.

References C4Fixed().

196 { return C4Fixed(*this) /= iVal2; }
C4Fixed()
Definition: C4Real.h:77

Here is the call graph for this function:

C4Fixed C4Fixed::operator/ ( float  iVal2) const
inline

Definition at line 201 of file C4Real.h.

References C4Fixed().

201 { return C4Fixed(*this) /= iVal2; }
C4Fixed()
Definition: C4Real.h:77

Here is the call graph for this function:

C4Fixed& C4Fixed::operator/= ( const C4Fixed fVal2)
inline

Definition at line 158 of file C4Real.h.

References FIXED_FPF, and val.

159  {
160  val = int32_t( (int64_t(val) * FIXED_FPF) / fVal2.val );
161  return *this;
162  }
#define FIXED_FPF
Definition: C4Real.h:56
int32_t val
Definition: C4Real.h:73
C4Fixed& C4Fixed::operator/= ( int32_t  iVal2)
inline

Definition at line 163 of file C4Real.h.

164  {
165  val /= iVal2;
166  return *this;
167  }
int32_t val
Definition: C4Real.h:73
bool C4Fixed::operator< ( const C4Fixed fVal2) const
inline

Definition at line 178 of file C4Real.h.

References val.

Referenced by operator<().

178 { return val<fVal2.val; }
int32_t val
Definition: C4Real.h:73

Here is the caller graph for this function:

bool C4Fixed::operator< ( int32_t  iVal2) const
inline

Definition at line 204 of file C4Real.h.

References C4Fixed(), and operator<().

204 { return operator < (C4Fixed(iVal2)); }
bool operator<(const C4Fixed &fVal2) const
Definition: C4Real.h:178
C4Fixed()
Definition: C4Real.h:77

Here is the call graph for this function:

bool C4Fixed::operator< ( float  iVal2) const
inline

Definition at line 211 of file C4Real.h.

References C4Fixed(), and operator<().

211 { return operator < (C4Fixed(iVal2)); }
bool operator<(const C4Fixed &fVal2) const
Definition: C4Real.h:178
C4Fixed()
Definition: C4Real.h:77

Here is the call graph for this function:

bool C4Fixed::operator<= ( const C4Fixed fVal2) const
inline

Definition at line 180 of file C4Real.h.

References val.

Referenced by operator<=().

180 { return val<=fVal2.val; }
int32_t val
Definition: C4Real.h:73

Here is the caller graph for this function:

bool C4Fixed::operator<= ( int32_t  iVal2) const
inline

Definition at line 206 of file C4Real.h.

References C4Fixed(), and operator<=().

206 { return operator <= (C4Fixed(iVal2)); }
bool operator<=(const C4Fixed &fVal2) const
Definition: C4Real.h:180
C4Fixed()
Definition: C4Real.h:77

Here is the call graph for this function:

bool C4Fixed::operator<= ( float  iVal2) const
inline

Definition at line 213 of file C4Real.h.

References C4Fixed(), and operator<=().

213 { return operator <= (C4Fixed(iVal2)); }
bool operator<=(const C4Fixed &fVal2) const
Definition: C4Real.h:180
C4Fixed()
Definition: C4Real.h:77

Here is the call graph for this function:

C4Fixed& C4Fixed::operator= ( int32_t  x)
inline

Definition at line 123 of file C4Real.h.

References C4Fixed().

123 { return *this = C4Fixed(x); }
C4Fixed()
Definition: C4Real.h:77

Here is the call graph for this function:

bool C4Fixed::operator== ( const C4Fixed fVal2) const
inline

Definition at line 177 of file C4Real.h.

References val.

Referenced by operator==().

177 { return val==fVal2.val; }
int32_t val
Definition: C4Real.h:73

Here is the caller graph for this function:

bool C4Fixed::operator== ( int32_t  iVal2) const
inline

Definition at line 203 of file C4Real.h.

References C4Fixed(), and operator==().

203 { return operator == (C4Fixed(iVal2)); }
bool operator==(const C4Fixed &fVal2) const
Definition: C4Real.h:177
C4Fixed()
Definition: C4Real.h:77

Here is the call graph for this function:

bool C4Fixed::operator== ( float  iVal2) const
inline

Definition at line 210 of file C4Real.h.

References C4Fixed(), and operator==().

210 { return operator == (C4Fixed(iVal2)); }
bool operator==(const C4Fixed &fVal2) const
Definition: C4Real.h:177
C4Fixed()
Definition: C4Real.h:77

Here is the call graph for this function:

bool C4Fixed::operator> ( const C4Fixed fVal2) const
inline

Definition at line 179 of file C4Real.h.

References val.

Referenced by operator>().

179 { return val>fVal2.val; }
int32_t val
Definition: C4Real.h:73

Here is the caller graph for this function:

bool C4Fixed::operator> ( int32_t  iVal2) const
inline

Definition at line 205 of file C4Real.h.

References C4Fixed(), and operator>().

205 { return operator > (C4Fixed(iVal2)); }
bool operator>(const C4Fixed &fVal2) const
Definition: C4Real.h:179
C4Fixed()
Definition: C4Real.h:77

Here is the call graph for this function:

bool C4Fixed::operator> ( float  iVal2) const
inline

Definition at line 212 of file C4Real.h.

References C4Fixed(), and operator>().

212 { return operator > (C4Fixed(iVal2)); }
bool operator>(const C4Fixed &fVal2) const
Definition: C4Real.h:179
C4Fixed()
Definition: C4Real.h:77

Here is the call graph for this function:

bool C4Fixed::operator>= ( const C4Fixed fVal2) const
inline

Definition at line 181 of file C4Real.h.

References val.

Referenced by operator>=().

181 { return val>=fVal2.val; }
int32_t val
Definition: C4Real.h:73

Here is the caller graph for this function:

bool C4Fixed::operator>= ( int32_t  iVal2) const
inline

Definition at line 207 of file C4Real.h.

References C4Fixed(), and operator>=().

207 { return operator >= (C4Fixed(iVal2)); }
bool operator>=(const C4Fixed &fVal2) const
Definition: C4Real.h:181
C4Fixed()
Definition: C4Real.h:77

Here is the call graph for this function:

bool C4Fixed::operator>= ( float  iVal2) const
inline

Definition at line 214 of file C4Real.h.

References C4Fixed(), and operator>=().

214 { return operator >= (C4Fixed(iVal2)); }
bool operator>=(const C4Fixed &fVal2) const
Definition: C4Real.h:181
C4Fixed()
Definition: C4Real.h:77

Here is the call graph for this function:

C4Fixed C4Fixed::sin_deg ( ) const
inline

Definition at line 218 of file C4Real.h.

References FIXED_FPF, SineTable, and val.

Referenced by Sin().

219  {
220  // adjust angle
221  int32_t v=int32_t((int64_t(val)*100)/FIXED_FPF); if (v<0) v=18000-v; v%=36000;
222  // get sine
223  C4Fixed fr;
224  switch (v/9000)
225  {
226  case 0: fr.val=+SineTable[v]; break;
227  case 1: fr.val=+SineTable[18000-v]; break;
228  case 2: fr.val=-SineTable[v-18000]; break;
229  case 3: fr.val=-SineTable[36000-v]; break;
230  }
231  return fr;
232  }
Definition: C4Real.h:58
long SineTable[9001]
#define FIXED_FPF
Definition: C4Real.h:56
int32_t val
Definition: C4Real.h:73

Here is the caller graph for this function:

Friends And Related Function Documentation

void CompileFunc ( C4Fixed rValue,
StdCompiler pComp 
)
friend

Definition at line 9033 of file C4Real.cpp.

9034 {
9035 #ifdef C4REAL_USE_FIXNUM
9036  char cFormat = 'F';
9037 #else
9038  char cFormat = 'f';
9039 #endif
9040  try
9041  {
9042  // Read/write type
9043  pComp->Character(cFormat);
9044 
9045  }
9046  catch (StdCompiler::NotFoundException *pEx)
9047  {
9048  delete pEx;
9049  // Expect old format if not found
9050  cFormat = 'F';
9051  }
9052  // Read value (as int32_t)
9053  pComp->Value(mkCastAdapt<int32_t>(rValue));
9054  // convert, if neccessary
9055 #ifdef C4REAL_USE_FIXNUM
9056  if (cFormat == 'f')
9057  FLOAT_TO_FIXED(&rValue);
9058 #else
9059  if (cFormat == 'F')
9060  FIXED_TO_FLOAT(&rValue);
9061 #endif
9062 }
void Value(const T &rStruct)
Definition: StdCompiler.h:171
virtual void Character(char &rChar)=0
void FLOAT_TO_FIXED(C4Real *pVal)
Definition: C4Real.h:318
float fixtof ( const C4Fixed x)
friend

Definition at line 257 of file C4Real.h.

257 { return x.to_float(); }
int fixtoi ( const C4Fixed x)
friend

Definition at line 259 of file C4Real.h.

259 { return x.to_int(); }
int fixtoi ( const C4Fixed x,
int32_t  prec 
)
friend

Definition at line 260 of file C4Real.h.

260 { return x.to_int(prec); }
C4Fixed ftofix ( float  x)
friend

Definition at line 258 of file C4Real.h.

258 { return C4Fixed(x); }
C4Fixed()
Definition: C4Real.h:77
C4Fixed itofix ( int32_t  x)
friend

Definition at line 261 of file C4Real.h.

261 { return C4Fixed(x); }
C4Fixed()
Definition: C4Real.h:77
C4Fixed itofix ( int32_t  x,
int32_t  prec 
)
friend

Definition at line 262 of file C4Real.h.

262 { return C4Fixed(x, prec); }
C4Fixed()
Definition: C4Real.h:77

Member Data Documentation


The documentation for this class was generated from the following file: