The power of truetype font rendering!
[ipdf/code.git] / src / real.h
1 #ifndef _REAL_H
2 #define _REAL_H
3
4 #include "common.h"
5
6
7 #define REAL_SINGLE 0
8 #define REAL_DOUBLE 1
9 #define REAL_LONG_DOUBLE 2
10 #define REAL_VFPU 3
11 #define REAL_RATIONAL 4
12 #define REAL_RATIONAL_ARBINT 5
13
14 #ifndef REAL
15         #error "REAL was not defined!"
16 #endif
17
18 #if REAL == REAL_VFPU
19         #include "vfpu.h"
20 #endif
21
22 #if REAL == REAL_RATIONAL
23         #include "rational.h"
24 #endif //REAL
25
26 #if REAL == REAL_RATIONAL_ARBINT
27         #include "rational.h"
28         #include "arbint.h"
29         #include "gmpint.h"
30 #endif //REAL
31
32 namespace IPDF
33 {       
34         extern const char * g_real_name[];
35
36 #if REAL == REAL_SINGLE
37         typedef float Real;
38 #elif REAL == REAL_DOUBLE
39         typedef double Real;
40 #elif REAL == REAL_LONG_DOUBLE
41         typedef long double Real;
42 #elif REAL == REAL_VFPU
43         typedef VFPU::VFloat Real;
44         inline float Float(const Real & r) {return r.m_value;}
45         inline double Double(const Real & r) {return r.m_value;}
46 #elif REAL == REAL_RATIONAL
47         typedef Rational<int64_t> Real;
48         inline float Float(const Real & r) {return (float)r.ToDouble();}
49         inline double Double(const Real & r) {return r.ToDouble();}
50 #elif REAL == REAL_RATIONAL_ARBINT
51         #define ARBINT Gmpint // Set to Gmpint or Arbint here
52         
53         typedef Rational<ARBINT> Real;
54         inline float Float(const Real & r) {return (float)r.ToDouble();}
55         inline double Double(const Real & r) {return r.ToDouble();}
56
57 #else
58         #error "Type of Real unspecified."
59 #endif //REAL
60
61         // Allow us to call Float on the primative types
62         // Useful so I can template some things that could be either (a more complicated) Real or a primitive type
63         // Mostly in the testers.
64         inline float Float(float f) {return (float)f;}
65         inline float Float(double f) {return (float)f;}
66         inline float Float(long double f) {return (float)(f);}
67         inline double Double(float f) {return (double)f;}
68         inline double Double(double f) {return (double)f;}
69         inline double Double(long double f) {return (double)(f);}
70         
71         inline Real Power(const Real & a, int n)
72         {
73                 if (n < 0)
74                 {
75                         return Power(Real(1)/a, -n);
76                 }
77                 Real r(1);
78                 for (int i = 0; i < n; ++i)
79                         r *= a;
80                 return r;
81         }
82         
83 }
84
85 #endif //_REAL_H

UCC git Repository :: git.ucc.asn.au