Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

mpeg3real.h

Go to the documentation of this file.
00001 /**********************************************************************
00002 ** Copyright (C) 2000 Trolltech AS.  All rights reserved.
00003 **
00004 ** This file is part of Qtopia Environment.
00005 **
00006 ** This file may be distributed and/or modified under the terms of the
00007 ** GNU General Public License version 2 as published by the Free Software
00008 ** Foundation and appearing in the file LICENSE.GPL included in the
00009 ** packaging of this file.
00010 **
00011 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
00012 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
00013 **
00014 ** See http://www.trolltech.com/gpl/ for GPL licensing information.
00015 **
00016 ** Contact info@trolltech.com if any conditions of this licensing are
00017 ** not clear to you.
00018 **
00019 **********************************************************************/
00020 #ifndef MPEG3REAL_H
00021 #define MPEG3REAL_H
00022 
00023 #ifdef USE_FIXED_POINT
00024 
00025 #include <limits.h>
00026 #include <stdio.h>
00027 
00028 #ifndef LONGLONG
00029 #define LONGLONG long long
00030 #endif
00031 
00032 //#define SC (1<<16)
00033 #define SC (1<<15)
00034 
00035 class mpeg3_real_t {
00036     long v;
00037 public:
00038     mpeg3_real_t() { } // Uninitialized, just like a float
00039     mpeg3_real_t(double d) { v=long(d*SC); }
00040     mpeg3_real_t(float f) { v=long(f*SC); }
00041     mpeg3_real_t(int i) { v=long(i*SC); }
00042     long fixedPoint() const { return v; }
00043     operator float() const { return ((float)v)/SC; }
00044     operator int() const { return (int)(v/SC); }
00045     mpeg3_real_t operator+() const;
00046     mpeg3_real_t operator-() const;
00047     mpeg3_real_t& operator= (const mpeg3_real_t&);
00048     mpeg3_real_t& operator+= (const mpeg3_real_t&);
00049     mpeg3_real_t& operator-= (const mpeg3_real_t&);
00050     mpeg3_real_t& operator*= (const mpeg3_real_t&);
00051     mpeg3_real_t& operator/= (const mpeg3_real_t&);
00052     friend mpeg3_real_t operator+ (const mpeg3_real_t&, const mpeg3_real_t&);
00053     friend mpeg3_real_t operator- (const mpeg3_real_t&, const mpeg3_real_t&);
00054     friend mpeg3_real_t operator* (const mpeg3_real_t&, const mpeg3_real_t&);
00055     friend mpeg3_real_t operator/ (const mpeg3_real_t&, const mpeg3_real_t&);
00056     friend mpeg3_real_t operator+ (const mpeg3_real_t&, const float&);
00057     friend mpeg3_real_t operator- (const mpeg3_real_t&, const float&);
00058     friend mpeg3_real_t operator* (const mpeg3_real_t&, const float&);
00059     friend mpeg3_real_t operator/ (const mpeg3_real_t&, const float&);
00060     friend mpeg3_real_t operator+ (const float&, const mpeg3_real_t&);
00061     friend mpeg3_real_t operator- (const float&, const mpeg3_real_t&);
00062     friend mpeg3_real_t operator* (const float&, const mpeg3_real_t&);
00063     friend mpeg3_real_t operator/ (const float&, const mpeg3_real_t&);
00064     friend mpeg3_real_t operator+ (const mpeg3_real_t&, const int&);
00065     friend mpeg3_real_t operator- (const mpeg3_real_t&, const int&);
00066     friend mpeg3_real_t operator* (const mpeg3_real_t&, const int&);
00067     friend mpeg3_real_t operator/ (const mpeg3_real_t&, const int&);
00068     friend mpeg3_real_t operator+ (const int&, const mpeg3_real_t&);
00069     friend mpeg3_real_t operator- (const int&, const mpeg3_real_t&);
00070     friend mpeg3_real_t operator* (const int&, const mpeg3_real_t&);
00071     friend mpeg3_real_t operator/ (const int&, const mpeg3_real_t&);
00072 };
00073 
00074 inline mpeg3_real_t mpeg3_real_t::operator+() const
00075 {
00076     return *this;
00077 }
00078 
00079 inline mpeg3_real_t mpeg3_real_t::operator-() const
00080 {
00081     mpeg3_real_t r;
00082     r.v=-v;
00083     return r;
00084 }
00085 
00086 inline mpeg3_real_t& mpeg3_real_t::operator= (const mpeg3_real_t& o)
00087 {
00088     v=o.v;
00089     return *this;
00090 }
00091 
00092 inline mpeg3_real_t& mpeg3_real_t::operator+= (const mpeg3_real_t& o)
00093 {
00094     v += o.v;
00095     return *this;
00096 }
00097 
00098 inline mpeg3_real_t& mpeg3_real_t::operator-= (const mpeg3_real_t& o)
00099 {
00100     v -= o.v;
00101     return *this;
00102 }
00103 
00104 inline mpeg3_real_t& mpeg3_real_t::operator*= (const mpeg3_real_t& o)
00105 {
00106     *this = *this * o;
00107     return *this;
00108 }
00109 
00110 inline mpeg3_real_t& mpeg3_real_t::operator/= (const mpeg3_real_t& o)
00111 {
00112     *this = *this / o; 
00113     return *this;
00114 }
00115 
00116 
00117 inline mpeg3_real_t operator+ (const mpeg3_real_t&a, const mpeg3_real_t&b)
00118 {
00119     mpeg3_real_t r;
00120     r.v=a.v+b.v;
00121     return r;
00122 }
00123 
00124 inline mpeg3_real_t operator- (const mpeg3_real_t&a, const mpeg3_real_t&b)
00125 {
00126     mpeg3_real_t r;
00127     r.v=a.v-b.v;
00128     return r;
00129 }
00130 
00131 inline mpeg3_real_t operator* (const mpeg3_real_t&a, const mpeg3_real_t&b)
00132 {
00133     mpeg3_real_t r;
00134     r.v = (LONGLONG)a.v * b.v / SC;
00135     return r;
00136 }
00137 
00138 inline mpeg3_real_t operator/ (const mpeg3_real_t&a, const mpeg3_real_t&b)
00139 {
00140     mpeg3_real_t r;
00141     r.v = (LONGLONG)a.v * SC / b.v;
00142     return r;
00143 }
00144 
00145 inline mpeg3_real_t operator+ (const mpeg3_real_t&a, const float&b)
00146 {
00147     return a+mpeg3_real_t(b);
00148 }
00149 
00150 inline mpeg3_real_t operator- (const mpeg3_real_t&a, const float&b)
00151 {
00152     return a-mpeg3_real_t(b);
00153 }
00154 
00155 inline mpeg3_real_t operator* (const mpeg3_real_t&a, const float&b)
00156 {
00157     return a*mpeg3_real_t(b);
00158 }
00159 
00160 inline mpeg3_real_t operator/ (const mpeg3_real_t&a, const float&b)
00161 {
00162     return a/mpeg3_real_t(b);
00163 }
00164 
00165 
00166 inline mpeg3_real_t operator+ (const float&a, const mpeg3_real_t&b)
00167 {
00168     return mpeg3_real_t(a)+b;
00169 }
00170 
00171 inline mpeg3_real_t operator- (const float&a, const mpeg3_real_t&b)
00172 {
00173     return mpeg3_real_t(a)-b;
00174 }
00175 
00176 inline mpeg3_real_t operator* (const float&a, const mpeg3_real_t&b)
00177 {
00178     return mpeg3_real_t(a)*b;
00179 }
00180 
00181 inline mpeg3_real_t operator/ (const float&a, const mpeg3_real_t&b)
00182 {
00183     return mpeg3_real_t(a)/b;
00184 }
00185 
00186 
00187 inline mpeg3_real_t operator+ (const mpeg3_real_t&a, const int&b)
00188 {
00189     return a+mpeg3_real_t(b);
00190 }
00191 
00192 inline mpeg3_real_t operator- (const mpeg3_real_t&a, const int&b)
00193 {
00194     return a-mpeg3_real_t(b);
00195 }
00196 
00197 inline mpeg3_real_t operator* (const mpeg3_real_t&a, const int&b)
00198 {
00199     return a*mpeg3_real_t(b);
00200 }
00201 
00202 inline mpeg3_real_t operator/ (const mpeg3_real_t&a, const int&b)
00203 {
00204     return a/mpeg3_real_t(b);
00205 }
00206 
00207 
00208 inline mpeg3_real_t operator+ (const int&a, const mpeg3_real_t&b)
00209 {
00210     return mpeg3_real_t(a)+b;
00211 }
00212 
00213 inline mpeg3_real_t operator- (const int&a, const mpeg3_real_t&b)
00214 {
00215     return mpeg3_real_t(a)-b;
00216 }
00217 
00218 inline mpeg3_real_t operator* (const int&a, const mpeg3_real_t&b)
00219 {
00220     return mpeg3_real_t(a)*b;
00221 }
00222 
00223 inline mpeg3_real_t operator/ (const int&a, const mpeg3_real_t&b)
00224 {
00225     return mpeg3_real_t(a)/b;
00226 }
00227 
00228 #else
00229 typedef float mpeg3_real_t;
00230 #endif
00231 
00232 #endif

Generated on Sat Nov 5 16:15:37 2005 for OPIE by  doxygen 1.4.2