fixedfloat26_6.h

00001 /***************************************************************************
00002  *   Copyright (C) 2004 by Jacques Gasselin                                *
00003  *   jacquesgasselin@hotmail.com                                           *
00004  *                                                                         *
00005  *   This program is free software; you can redistribute it and/or modify  *
00006  *   it under the terms of the GNU Library General Public License as       *
00007  *   published by the Free Software Foundation; either version 2 of the    *
00008  *   License, or (at your option) any later version.                       *
00009  *                                                                         *
00010  *   This program 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         *
00013  *   GNU 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 program; if not, write to the                 *
00017  *   Free Software Foundation, Inc.,                                       *
00018  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
00019  ***************************************************************************/
00020 #ifndef MATHGLPPFIXEDFLOAT26_6_H
00021 #define MATHGLPPFIXEDFLOAT26_6_H
00022 
00023 namespace mathglpp {
00024 
00031 class FixedFloat26_6
00032 {
00033 public:
00034     FixedFloat26_6(char c):val(int(c)<<6){}
00035     FixedFloat26_6(short s):val(int(s)<<6){}
00036     FixedFloat26_6(int i):val(i<<6){}
00037     FixedFloat26_6(float f):val(int(f*64.0f)){}
00038     FixedFloat26_6(double d):val(int(d*64.0)){}
00039     FixedFloat26_6(const FixedFloat26_6& ff):val(ff.val){}
00040     ~FixedFloat26_6(){}
00041 
00042     inline FixedFloat26_6 operator +(const FixedFloat26_6& ff) const
00043     {   FixedFloat26_6 ret(*this); ret+=ff; return ret; }
00044 
00045     inline FixedFloat26_6& operator +=(const FixedFloat26_6& ff)
00046     {   val+=ff.val; return *this; }
00047 
00048     inline FixedFloat26_6 operator -(const FixedFloat26_6& ff) const
00049     {   FixedFloat26_6 ret(*this); ret+=ff; return ret; }
00050 
00051     inline FixedFloat26_6& operator -=(const FixedFloat26_6& ff)
00052     {   val+=ff.val; return *this; }
00053 
00054     inline FixedFloat26_6 operator *(const FixedFloat26_6& ff) const
00055     {   FixedFloat26_6 ret(*this); ret*=ff; return ret; }
00056 
00057     inline FixedFloat26_6& operator *=(const FixedFloat26_6& ff)
00058     {   val = int((val/64.0)*(ff.val/64.0)*64.0); return *this; }
00059 
00060     inline FixedFloat26_6 operator /(const FixedFloat26_6& ff) const
00061     {   FixedFloat26_6 ret(*this); ret*=ff; return ret; }
00062 
00063     inline FixedFloat26_6& operator /=(const FixedFloat26_6& ff)
00064     {   val = int((val/64.0)/(ff.val/64.0)*64.0); return *this; }
00065 
00066     inline bool operator ==(const FixedFloat26_6& ff) const
00067     {   return val == ff.val; }
00068 
00069     inline operator int() const { return val; }
00070 
00071     inline char toChar() const { return char(val>>6); }
00072     inline short toShort() const { return short(val>>6); }
00073     inline int toInt() const { return int(val>>6); }
00074     inline float toFloat() const { return float(val/64.0f); }
00075     inline double toDouble() const { return double(val/64.0); }
00076 
00077 private:
00078     int val;
00079 };
00080 
00081 typedef FixedFloat26_6 float26_6;
00082 };
00083 
00084 #endif

Generated on Wed Oct 3 12:50:48 2007 for MathGL++ by  doxygen 1.5.2