Add VFPU::Float (but it is broken)
[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::Float 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         
48         typedef Rational<int64_t> Real;
49         inline float Float(const Real & r) {return (float)r.ToDouble();}
50         inline double Double(const Real & r) {return r.ToDouble();}
51 #elif REAL == REAL_RATIONAL_ARBINT
52         #define ARBINT Gmpint // Set to Gmpint or Arbint here
53         
54         typedef Rational<ARBINT> Real;
55         inline float Float(const Real & r) {return (float)r.ToDouble();}
56         inline double Double(const Real & r) {return r.ToDouble();}
57         inline Rational<ARBINT> pow(const Rational<ARBINT> & a, const Rational<ARBINT> & b)
58         {
59                 ARBINT P(std::pow(static_cast<double>(a.P), b.ToDouble()));
60                 ARBINT Q(std::pow(static_cast<double>(a.Q), b.ToDouble()));
61                 return Rational<ARBINT>(P,Q);
62         }
63 #else
64         #error "Type of Real unspecified."
65 #endif //REAL
66
67         // Allow us to call Float on the primative types
68         // Useful so I can template some things that could be either (a more complicated) Real or a primitive type
69         // Mostly in the testers.
70         inline float Float(float f) {return (float)f;}
71         inline float Float(double f) {return (float)f;}
72         inline float Float(long double f) {return (float)(f);}
73         inline double Double(float f) {return (double)f;}
74         inline double Double(double f) {return (double)f;}
75         inline double Double(long double f) {return (double)(f);}
76 }
77
78 #endif //_REAL_H

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