Fixed.h

Go to the documentation of this file.
00001 #ifndef JAVA_UTIL_FIXED_H
00002 #define JAVA_UTIL_FIXED_H 1
00003 
00004 #ifndef JAVA_LANG_OBJECT_H
00005 #include <java_lang/Object.h>
00006 #endif /* JAVA_LANG_OBJECT_H */
00007 
00008 #define USE_FP
00009 
00010 #define DEGREE_PI 1800
00011 #define DEGREE_2PI (DEGREE_PI*2)
00012 #define DEGREE_PI2 (DEGREE_PI/2)
00013 
00014 #if defined(USE_FP)
00015 
00016 typedef jdouble Fixed;
00017 
00018 #  define ZERO (0.0)
00019 #  define ONE (1.0)
00020 #  define FIXED(v,p) ((p == 3) ? 0.001*v : v)
00021 
00022 #else
00023 
00024 #  define DEFAULT_PRECISION (3)
00025 #  define ZERO Fixed(0, DEFAULT_PRECISION)
00026 #  define ONE Fixed(1000, DEFAULT_PRECISION)
00027 #  define FIXED(v,p) Fixed(v,p)
00028 
00029 namespace java {
00030   namespace util {
00031 
00039     class JAVA_UTIL_SPEC Fixed : public Object {
00040     public:
00041 
00042       Fixed();
00043       Fixed(jint value);
00044       Fixed(jint value, jint precision);
00045       Fixed(jdouble d);
00046       Fixed(const String& s);
00047       Fixed operator[](jint pecision) const;
00048       virtual jboolean equals(const Object& o) const;
00049       virtual jboolean equals(const Fixed& f) const;
00050       virtual jint hashCode() const;
00051       virtual String toString() const;
00052       virtual String toHexString() const;
00053       operator jdouble() const;
00054       operator jint() const;
00055       Fixed& operator=(const Fixed& f);
00056       Fixed& operator=(jint i);
00057       Fixed& operator+=(const Fixed& f);
00058       Fixed& operator-=(const Fixed& f);
00059       Fixed& operator*=(const Fixed& f);
00060       Fixed& operator*=(jint i);
00061       Fixed& operator/=(const Fixed& f);
00062       Fixed& operator/=(jint i);
00063       Fixed operator-() const;
00064       Fixed operator+(const Fixed& f) const;
00065       Fixed operator-(const Fixed& f) const;
00066       Fixed operator*(const Fixed& f) const;
00067       Fixed operator*(jint i) const;
00068       Fixed operator/(const Fixed& f) const;
00069       Fixed operator/(jint i) const;
00070       jboolean operator==(const Fixed& f) const;
00071       jboolean operator!=(const Fixed& f) const;
00072       jboolean operator<=(const Fixed& f) const;
00073       jboolean operator>=(const Fixed& f) const;
00074       jboolean operator<(const Fixed& f) const;
00075       jboolean operator>(const Fixed& f) const;
00076 
00077     protected:
00078 
00079       void equalize_precision(Fixed &f);
00080 
00081     private:
00082 
00083       jint value;
00084       jint precision;
00085       REGISTER_MEMBERS;
00086 
00087     };
00088 
00089     inline Fixed operator+(jint x, const Fixed& y) { return Fixed(x)+y;}
00090     inline Fixed operator-(jint x, const Fixed& y) { return Fixed(x)-y;}
00091     inline Fixed operator*(jint x, const Fixed& y) { return Fixed(x)*y;}
00092     inline Fixed operator/(jint x, const Fixed& y) { return Fixed(x)/y;}
00093     inline jboolean operator==(jint x, const Fixed& y) { return Fixed(x) == y;}
00094     inline jboolean operator!=(jint x, const Fixed& y) { return Fixed(x) != y;}
00095     inline jboolean operator>=(jint x, const Fixed& y) { return Fixed(x) >= y;}
00096     inline jboolean operator<=(jint x, const Fixed& y) { return Fixed(x) <= y;}
00097     inline jboolean operator>(jint x, const Fixed& y) { return Fixed(x) > y;}
00098     inline jboolean operator<(jint x, const Fixed& y) { return Fixed(x) < y;}
00099 
00100   } // namespace util
00101 } // namespace java
00102 
00103 #endif
00104 
00105 namespace java {
00106   namespace util {
00107 
00108     class JAVA_UTIL_SPEC FMath : public Object {
00109     public:
00110       static Fixed abs(const Fixed& f);
00111       static Fixed sin(jint deg);
00112       static Fixed cos(jint deg);
00113       static jint asin(const Fixed& f);
00114       static jint acos(const Fixed& f);
00115       static jint round(const Fixed& f);
00116       static Fixed ceil(const Fixed& f);
00117       static Fixed floor(const Fixed& f);
00118       static Fixed exp2(const Fixed& f);
00119       static Fixed log2(const Fixed& f);
00120       static Fixed sqrt(const Fixed& f);
00121     private:
00122       REGISTER_MEMBERS;
00123     };
00124 
00125   } // namespace util
00126 } // namespace java
00127 
00128 #endif /* JAVA_UTIL_FIXED_H */

Generated on Fri May 16 11:54:43 2008 for CrossPlatformJavaLikeC++API by  doxygen 1.5.3