OpenClonk
C4Fixed Class Reference

#include <C4Real.h>

Public Member Functions

 C4Fixed ()=default
 
 C4Fixed (const C4Fixed &)=default
 
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() [1/2]

C4Fixed::C4Fixed ( )
inlinedefault

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

Here is the caller graph for this function:

◆ C4Fixed() [2/2]

C4Fixed::C4Fixed ( const C4Fixed )
inlinedefault

Member Function Documentation

◆ cos_deg()

C4Fixed C4Fixed::cos_deg ( ) const
inline

Definition at line 233 of file C4Real.h.

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  }
#define FIXED_FPF
Definition: C4Real.h:56
long SineTable[9001]
Definition: C4Real.h:59
int32_t val
Definition: C4Real.h:73

References FIXED_FPF, SineTable, and val.

Referenced by Cos().

Here is the caller graph for this function:

◆ operator bool()

C4Fixed::operator bool ( ) const
inlineexplicit

Definition at line 126 of file C4Real.h.

126 { return val != 0; }

References val.

◆ operator!()

bool C4Fixed::operator! ( ) const
inline

Definition at line 127 of file C4Real.h.

127 { return ! val; }

References val.

◆ operator!=() [1/3]

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

Definition at line 182 of file C4Real.h.

182 { return val!=fVal2.val; }

References val.

Referenced by operator!=().

Here is the caller graph for this function:

◆ operator!=() [2/3]

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

Definition at line 215 of file C4Real.h.

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

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

Here is the call graph for this function:

◆ operator!=() [3/3]

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

Definition at line 208 of file C4Real.h.

208 { return operator != (C4Fixed(iVal2)); }

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

Here is the call graph for this function:

◆ operator*() [1/3]

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

Definition at line 190 of file C4Real.h.

190 { return C4Fixed(*this) *= fVal2; }

References C4Fixed().

Here is the call graph for this function:

◆ operator*() [2/3]

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

Definition at line 200 of file C4Real.h.

200 { return C4Fixed(*this) *= iVal2; }

References C4Fixed().

Here is the call graph for this function:

◆ operator*() [3/3]

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

Definition at line 195 of file C4Real.h.

195 { return C4Fixed(*this) *= iVal2; }

References C4Fixed().

Here is the call graph for this function:

◆ operator*=() [1/2]

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

Definition at line 140 of file C4Real.h.

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_SHIFT
Definition: C4Real.h:54

References FIXED_FPF, FIXED_SHIFT, and val.

◆ operator*=() [2/2]

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

Definition at line 153 of file C4Real.h.

154  {
155  val *= iVal2;
156  return *this;
157  }

References val.

◆ operator+() [1/4]

C4Fixed C4Fixed::operator+ ( ) const
inline

Definition at line 172 of file C4Real.h.

173  {
174  return *this;
175  }

◆ operator+() [2/4]

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

Definition at line 188 of file C4Real.h.

188 { return C4Fixed(*this) += fVal2; }

References C4Fixed().

Here is the call graph for this function:

◆ operator+() [3/4]

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

Definition at line 198 of file C4Real.h.

198 { return C4Fixed(*this) += iVal2; }

References C4Fixed().

Here is the call graph for this function:

◆ operator+() [4/4]

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

Definition at line 193 of file C4Real.h.

193 { return C4Fixed(*this) += iVal2; }

References C4Fixed().

Here is the call graph for this function:

◆ operator+=() [1/2]

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

Definition at line 130 of file C4Real.h.

131  {
132  val += fVal2.val;
133  return *this;
134  }

References val.

Referenced by operator+=().

Here is the caller graph for this function:

◆ operator+=() [2/2]

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

Definition at line 185 of file C4Real.h.

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

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

Here is the call graph for this function:

◆ operator-() [1/4]

C4Fixed C4Fixed::operator- ( ) const
inline

Definition at line 168 of file C4Real.h.

169  {
170  C4Fixed fr; fr.val=-val; return fr;
171  }

References val.

◆ operator-() [2/4]

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

Definition at line 189 of file C4Real.h.

189 { return C4Fixed(*this) -= fVal2; }

References C4Fixed().

Here is the call graph for this function:

◆ operator-() [3/4]

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

Definition at line 199 of file C4Real.h.

199 { return C4Fixed(*this) -= iVal2; }

References C4Fixed().

Here is the call graph for this function:

◆ operator-() [4/4]

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

Definition at line 194 of file C4Real.h.

194 { return C4Fixed(*this) -= iVal2; }

References C4Fixed().

Here is the call graph for this function:

◆ operator-=() [1/2]

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

Definition at line 135 of file C4Real.h.

136  {
137  val -= fVal2.val;
138  return *this;
139  }

References val.

Referenced by operator-=().

Here is the caller graph for this function:

◆ operator-=() [2/2]

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

Definition at line 186 of file C4Real.h.

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

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

Here is the call graph for this function:

◆ operator/() [1/3]

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

Definition at line 191 of file C4Real.h.

191 { return C4Fixed(*this) /= fVal2; }

References C4Fixed().

Here is the call graph for this function:

◆ operator/() [2/3]

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

Definition at line 201 of file C4Real.h.

201 { return C4Fixed(*this) /= iVal2; }

References C4Fixed().

Here is the call graph for this function:

◆ operator/() [3/3]

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

Definition at line 196 of file C4Real.h.

196 { return C4Fixed(*this) /= iVal2; }

References C4Fixed().

Here is the call graph for this function:

◆ operator/=() [1/2]

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

Definition at line 158 of file C4Real.h.

159  {
160  val = int32_t( (int64_t(val) * FIXED_FPF) / fVal2.val );
161  return *this;
162  }

References FIXED_FPF, and val.

◆ operator/=() [2/2]

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

Definition at line 163 of file C4Real.h.

164  {
165  val /= iVal2;
166  return *this;
167  }

References val.

◆ operator<() [1/3]

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

Definition at line 178 of file C4Real.h.

178 { return val<fVal2.val; }

References val.

Referenced by operator<().

Here is the caller graph for this function:

◆ operator<() [2/3]

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

Definition at line 211 of file C4Real.h.

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

References C4Fixed(), and operator<().

Here is the call graph for this function:

◆ operator<() [3/3]

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

Definition at line 204 of file C4Real.h.

204 { return operator < (C4Fixed(iVal2)); }

References C4Fixed(), and operator<().

Here is the call graph for this function:

◆ operator<=() [1/3]

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

Definition at line 180 of file C4Real.h.

180 { return val<=fVal2.val; }

References val.

Referenced by operator<=().

Here is the caller graph for this function:

◆ operator<=() [2/3]

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

Definition at line 213 of file C4Real.h.

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

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

Here is the call graph for this function:

◆ operator<=() [3/3]

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

Definition at line 206 of file C4Real.h.

206 { return operator <= (C4Fixed(iVal2)); }

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

Here is the call graph for this function:

◆ operator=()

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

Definition at line 123 of file C4Real.h.

123 { return *this = C4Fixed(x); }

References C4Fixed().

Here is the call graph for this function:

◆ operator==() [1/3]

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

Definition at line 177 of file C4Real.h.

177 { return val==fVal2.val; }

References val.

Referenced by operator==().

Here is the caller graph for this function:

◆ operator==() [2/3]

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

Definition at line 210 of file C4Real.h.

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

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

Here is the call graph for this function:

◆ operator==() [3/3]

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

Definition at line 203 of file C4Real.h.

203 { return operator == (C4Fixed(iVal2)); }

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

Here is the call graph for this function:

◆ operator>() [1/3]

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

Definition at line 179 of file C4Real.h.

179 { return val>fVal2.val; }

References val.

Referenced by operator>().

Here is the caller graph for this function:

◆ operator>() [2/3]

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

Definition at line 212 of file C4Real.h.

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

References C4Fixed(), and operator>().

Here is the call graph for this function:

◆ operator>() [3/3]

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

Definition at line 205 of file C4Real.h.

205 { return operator > (C4Fixed(iVal2)); }

References C4Fixed(), and operator>().

Here is the call graph for this function:

◆ operator>=() [1/3]

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

Definition at line 181 of file C4Real.h.

181 { return val>=fVal2.val; }

References val.

Referenced by operator>=().

Here is the caller graph for this function:

◆ operator>=() [2/3]

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

Definition at line 214 of file C4Real.h.

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

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

Here is the call graph for this function:

◆ operator>=() [3/3]

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

Definition at line 207 of file C4Real.h.

207 { return operator >= (C4Fixed(iVal2)); }

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

Here is the call graph for this function:

◆ sin_deg()

C4Fixed C4Fixed::sin_deg ( ) const
inline

Definition at line 218 of file C4Real.h.

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  }

References FIXED_FPF, SineTable, and val.

Referenced by Sin().

Here is the caller graph for this function:

Friends And Related Function Documentation

◆ CompileFunc

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 FLOAT_TO_FIXED(C4Real *pVal)
Definition: C4Real.h:318
virtual void Character(char &rChar)=0
void Value(const T &rStruct)
Definition: StdCompiler.h:161

◆ fixtof

float fixtof ( const C4Fixed x)
friend

Definition at line 257 of file C4Real.h.

257 { return x.to_float(); }

◆ fixtoi [1/2]

int fixtoi ( const C4Fixed x)
friend

Definition at line 259 of file C4Real.h.

259 { return x.to_int(); }

◆ fixtoi [2/2]

int fixtoi ( const C4Fixed x,
int32_t  prec 
)
friend

Definition at line 260 of file C4Real.h.

260 { return x.to_int(prec); }

◆ ftofix

C4Fixed ftofix ( float  x)
friend

Definition at line 258 of file C4Real.h.

258 { return C4Fixed(x); }

◆ itofix [1/2]

C4Fixed itofix ( int32_t  x)
friend

Definition at line 261 of file C4Real.h.

261 { return C4Fixed(x); }

◆ itofix [2/2]

C4Fixed itofix ( int32_t  x,
int32_t  prec 
)
friend

Definition at line 262 of file C4Real.h.

262 { return C4Fixed(x, prec); }

Member Data Documentation

◆ val


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