00001
00002
00003
00004
00005
00006
00007
00008
00009 #ifndef H__FIXED
00010 #define H__FIXED
00011
00012 #include <QString>
00013 #include <QChar>
00014
00015
00016 const int MAX_FIXED_PRECISION = 12;
00017 const int MAX_FIXED_LENGTH = 25;
00018
00019 typedef long long int Fixed_numerator;
00020
00021 inline long long int integer(Fixed_numerator x) {
00022 return (int) x;
00023 }
00024
00025
00026 class Fixed {
00027
00028 private:
00029 void fromFixed(const char *);
00030
00031 public:
00032 Fixed_numerator value;
00033 int precision;
00034 void equalize_precision(Fixed &);
00035 void setprecision(int);
00036
00037 public:
00038 Fixed(int x, int p);
00039 Fixed(QString a);
00040 Fixed(const char *a);
00041 Fixed();
00042 Fixed operator [] (int) const;
00043 Fixed operator = (Fixed);
00044 Fixed operator = (int);
00045 QString toQString(QChar separadorDecimal = ',');
00046 friend Fixed operator + (Fixed, Fixed);
00047 friend Fixed operator - (Fixed, Fixed);
00048 friend Fixed operator * (Fixed, Fixed);
00049 friend Fixed operator / (Fixed, Fixed);
00050 friend Fixed operator - (Fixed);
00051 friend bool operator == (Fixed, Fixed);
00052 friend bool operator < (Fixed, Fixed);
00053 friend Fixed operator - (int, Fixed);
00054 friend Fixed operator / (int, Fixed);
00055 friend bool operator == (int, Fixed);
00056 friend bool operator < (int, Fixed);
00057 friend Fixed operator + (Fixed, int);
00058 friend Fixed operator - (Fixed, int);
00059 friend Fixed operator * (Fixed, int);
00060 friend Fixed operator / (Fixed, int);
00061 friend bool operator == (Fixed, int);
00062 friend bool operator < (Fixed, int);
00063 enum {ALIGN = 1, COMMAS = 2, DECIMAL = 4};
00064 };
00065
00066
00067 inline bool operator != (Fixed x, Fixed y) {
00068 return !(x == y);
00069 }
00070
00071
00072 inline bool operator != (Fixed x, int y) {
00073 return !(x == y);
00074 }
00075
00076
00077 inline bool operator != (int x, Fixed y) {
00078 return !(x == y);
00079 }
00080
00081
00082 inline bool operator >= (Fixed x, Fixed y) {
00083 return !(x < y);
00084 }
00085
00086
00087 inline bool operator >= (Fixed x, int y) {
00088 return !(x < y);
00089 }
00090
00091
00092 inline bool operator >= (int x, Fixed y) {
00093 return !(x < y);
00094 }
00095
00096
00097 inline bool operator > (Fixed x, Fixed y) {
00098 return y < x;
00099 }
00100
00101
00102 inline bool operator > (Fixed x, int y) {
00103 return y < x;
00104 }
00105
00106
00107 inline bool operator > (int x, Fixed y) {
00108 return y < x;
00109 }
00110
00111
00112 inline bool operator <= (Fixed x, Fixed y) {
00113 return !(y < x);
00114 }
00115
00116
00117 inline bool operator <= (Fixed x, int y) {
00118 return !(y < x);
00119 }
00120
00121
00122 inline bool operator <= (int x, Fixed y) {
00123 return !(y < x);
00124 }
00125
00126 #endif
00127