SDPSL
Semidefinite Programming Specification Library
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Friends Pages
number.h
Go to the documentation of this file.
1 
7 #ifndef __NUMBER_H__
8 #define __NUMBER_H__
9 
10 #include <string>
11 #include <iostream>
12 #include <gmpxx.h>
13 #include <math.h>
14 
15 #ifdef __MPF_BUILD__
16 
17 namespace mpf_sdp {
18 
20 typedef mpf_class Number;
21 
22 #else
23 
24 namespace sdp {
25 
27 typedef double Number;
28 
29 #endif
30 
31 //
32 // Functions
33 //
34 
38 template <class T, class U>
39 inline T convert_number(const U& num) { return (T) num; }
40 
45 template <>
46 inline double convert_number(const mpf_class& num) { return num.get_d(); }
47 
54 public:
55  mpf_class operator()(double x) const { return mpf_class(x); }
56 };
57 
63  const Number& num;
64 
65 public:
67  explicit InsideCoefficient(const Number& n) : num(n) { }
68 
70  friend std::ostream& operator<<(std::ostream& out, const InsideCoefficient& ic);
71 };
72 
77 public:
81  static double abs(double num) { return num >= 0 ? num : -num; }
82 
86  static mpf_class abs(const mpf_class& num)
87  {
88  mpf_class ret;
89 
90  mpf_abs(ret.get_mpf_t(), num.get_mpf_t());
91 
92  return ret;
93  }
94 
98  static double sqrt(double num) { return ::sqrt(num); }
99 
103  static mpf_class sqrt(const mpf_class& num)
104  {
105  mpf_class ret;
106 
107  mpf_sqrt(ret.get_mpf_t(), num.get_mpf_t());
108 
109  return ret;
110  }
111 
117  static void from_string(const std::string& str, double& out);
118 
124  static void from_string(const std::string& str, mpf_class& out);
125 };
126 
127 //
128 // Prototypes
129 //
130 extern std::ostream& operator<<(std::ostream& out, const InsideCoefficient& ic);
131 
132 } // namespace
133 
134 #endif
135 
136 // Local variables:
137 // mode: c++
138 // End:
139