Add assembly sources to git
[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_SINGLE_FAST2SUM 3 //TODO: Remove, is FITH
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_SINGLE_FAST2SUM
19         #include "real_fast2sum.h"
20 #endif //REAL
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 #endif //REAL
30
31 namespace IPDF
32 {       
33         extern const char * g_real_name[];
34
35 #if REAL == REAL_SINGLE
36         typedef float Real;
37 #elif REAL == REAL_DOUBLE
38         typedef double Real;
39 #elif REAL == REAL_LONG_DOUBLE
40         typedef long double Real;
41 #elif REAL == REAL_SINGLE_FAST2SUM
42         typedef RealF2S<float> Real;
43         inline float Float(const Real & r) {return r.m_value;}
44         inline double Double(const Real & r) {return r.m_value;}
45 #elif REAL == REAL_RATIONAL
46         
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         typedef Rational<Arbint> Real;
52         inline float Float(const Real & r) {return (float)r.ToDouble();}
53         inline double Double(const Real & r) {return r.ToDouble();}
54         inline Rational<Arbint> pow(const Rational<Arbint> & a, const Rational<Arbint> & b)
55         {
56                 Arbint P(std::pow(static_cast<double>(a.P), b.ToDouble()));
57                 Arbint Q(std::pow(static_cast<double>(a.Q), b.ToDouble()));
58                 return Rational<Arbint>(P,Q);
59         }
60 #else
61         #error "Type of Real unspecified."
62 #endif //REAL
63
64         // Allow us to call Float on the primative types
65         // Useful so I can template some things that could be either (a more complicated) Real or a primitive type
66         // Mostly in the testers.
67         inline float Float(float f) {return (float)f;}
68         inline float Float(double f) {return (float)f;}
69         inline float Float(long double f) {return (float)(f);}
70         inline double Double(float f) {return (double)f;}
71         inline double Double(double f) {return (double)f;}
72         inline double Double(long double f) {return (double)(f);}
73 }
74
75 #endif //_REAL_H

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