## Public API Reference

- Main Page
- Modules
- Namespaces
- Classes
- Files
- Related Pages

- File List
- File Members

# csgeom/fixed.h

Go to the documentation of this file.

    00001 /*
    00002     Copyright (C) 2005 by Jorrit Tyberghein
    00003                   2005 by Frank Richter
    00004
    00005     This library is free software; you can redistribute it and/or
    00006     modify it under the terms of the GNU Library General Public
    00007     License as published by the Free Software Foundation; either
    00008     version 2 of the License, or (at your option) any later version.
    00009
    00010     This library is distributed in the hope that it will be useful,
    00011     but WITHOUT ANY WARRANTY; without even the implied warranty of
    00012     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    00013     Library General Public License for more details.
    00014
    00015     You should have received a copy of the GNU Library General Public
    00016     License along with this library; if not, write to the Free
    00017     Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
    00018 */
    00019
    00020 #ifndef __CS_CSGEOM_FIXED_H__
    00021 #define __CS_CSGEOM_FIXED_H__
    00022
    00023 #include "csqint.h"
    00024
    00036 class csFixed16
    00037 {
    00038   int32 v;
    00039 public:
    00041   csFixed16& operator= (float f)
    00042   {
    00043     v = csQfixed16 (f);
    00044     return *this;
    00045   }
    00046
    00048   inline friend csFixed16 operator- (const csFixed16& v1,
    00049     const csFixed16& v2)
    00050   {
    00051     csFixed16 v;
    00052     v.v = v1.v - v2.v;
    00053     return v;
    00054   }
    00056   inline friend csFixed16 operator- (float v1,
    00057     const csFixed16& v2)
    00058   {
    00059     csFixed16 v;
    00060     v.v = csQfixed16 (v1) - v2.v;
    00061     return v;
    00062   }
    00064   inline friend csFixed16 operator- (const csFixed16& v1,
    00065     float v2)
    00066   {
    00067     csFixed16 v;
    00068     v.v = v1.v - csQfixed16 (v2);
    00069     return v;
    00070   }
    00071
    00073   inline friend csFixed16 operator* (const csFixed16& v1,
    00074     float v2)
    00075   {
    00076     csFixed16 v;
    00077     v.v = (int32)(v1.v * v2);
    00078     return v;
    00079   }
    00080
    00082   inline csFixed16& operator+= (const csFixed16& x)
    00083   {
    00084     v += x.v;
    00085     return *this;
    00086   }
    00087
    00089   inline operator int() const
    00090   { return v >> 16; }
    00091
    00093   inline int32 GetFixed() const { return v; }
    00094
    00096   inline friend csFixed16 operator>> (const csFixed16& v1, int n)
    00097   {
    00098     csFixed16 vn;
    00099     vn.v = v1.v >> n;
    00100     return vn;
    00101   }
    00102 };
    00103
    00108 class csFixed24
    00109 {
    00110   int32 v;
    00111 public:
    00113   csFixed24& operator= (float f)
    00114   {
    00115     v = csQfixed24 (f);
    00116     return *this;
    00117   }
    00118
    00120   inline friend csFixed24 operator- (const csFixed24& v1,
    00121     const csFixed24& v2)
    00122   {
    00123     csFixed24 v;
    00124     v.v = v1.v - v2.v;
    00125     return v;
    00126   }
    00128   inline friend csFixed24 operator- (float v1,
    00129     const csFixed24& v2)
    00130   {
    00131     csFixed24 v;
    00132     v.v = csQfixed24 (v1) - v2.v;
    00133     return v;
    00134   }
    00136   inline friend csFixed24 operator- (const csFixed24& v1,
    00137     float v2)
    00138   {
    00139     csFixed24 v;
    00140     v.v = v1.v - csQfixed24 (v2);
    00141     return v;
    00142   }
    00143
    00145   inline friend csFixed24 operator* (const csFixed24& v1,
    00146     float v2)
    00147   {
    00148     csFixed24 v;
    00149     v.v = (int32)(v1.v * v2);
    00150     return v;
    00151   }
    00152
    00154   inline csFixed24& operator+= (const csFixed24& x)
    00155   {
    00156     v += x.v;
    00157     return *this;
    00158   }
    00159
    00161   inline operator int() const
    00162   { return v >> 16; }
    00163
    00165   inline int32 GetFixed() const { return v; }
    00166 };
    00167
    00170 #endif // __CS_CSGEOM_FIXED_H__
    00171