Camargue
fixed64.hpp
Go to the documentation of this file.
1 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
7 #ifndef CMR_FIXED64_H
8 #define CMR_FIXED64_H
9 
10 extern "C" {
11 #include <concorde/INCLUDE/bigguy.h>
12 }
13 
14 #include <iostream>
15 
16 namespace CMR {
17 namespace util {
18 
21 class Fixed64 {
22 public:
23  Fixed64() = default;
24 
25  Fixed64(int i) :
26  bg(CCbigguy_itobigguy(i)) {}
27 
28  Fixed64(double d) :
29  bg(CCbigguy_dtobigguy(d)) {};
30 
31 
32  double to_d() const
33  { return CCbigguy_bigguytod(bg); }
34 
36  { CCbigguy_add(&bg, f.bg); return *this; }
37 
39  { CCbigguy_sub(&bg, f.bg); return *this; }
40 
41  friend void add_mult(Fixed64 &f, const Fixed64 &g, int m);
42 
44  Fixed64 ceil() const
45  { Fixed64 result; result.bg = CCbigguy_ceil(bg); return result; }
46 
47 
48  bool operator<(const Fixed64 &f) const
49  { return CCbigguy_cmp(bg, f.bg) == -1; }
50 
51  bool operator==(const Fixed64 &f) const
52  { return CCbigguy_cmp(bg, f.bg) == 0; }
53 
54  bool operator!=(const Fixed64 &f) const
55  { return CCbigguy_cmp(bg, f.bg) != 0; }
56 
57  bool operator>(const Fixed64 &f) const
58  { return CCbigguy_cmp(bg, f.bg) == 1; }
59 
60  bool operator<=(const Fixed64 &f) const
61  { return CCbigguy_cmp(bg, f.bg) <= 0; }
62 
63  bool operator>=(const Fixed64 &f) const
64  { return CCbigguy_cmp(bg, f.bg) >= 0; }
65 
66 
67 private:
68  CCbigguy bg;
69 };
70 
71 inline Fixed64 operator+(Fixed64 a, Fixed64 b) { return a += b; }
72 inline Fixed64 operator-(Fixed64 a, Fixed64 b) { return a -= b; }
73 
74 inline void add_mult(Fixed64 &f, const Fixed64 &g, int m)
75 {
76  CCbigguy_addmult(&f.bg, g.bg, m);
77 }
78 
79 inline void add_mult(double &d, const double &g, int m)
80 {
81  d += m * g;
82 }
83 
84 inline std::ostream &operator<<(std::ostream &os, const Fixed64 &f)
85 {
86  os << (f.to_d());
87  return os;
88 }
89 
90 }
91 }
92 
93 #endif
Fixed64(int i)
Construct from integer.
Definition: fixed64.hpp:25
Fixed64 ceil() const
Integer ceiling.
Definition: fixed64.hpp:44
Fixed64 & operator+=(Fixed64 f)
Plus increment.
Definition: fixed64.hpp:35
CCbigguy bg
The underlying Concorde structure.
Definition: fixed64.hpp:68
Fixed64 & operator-=(Fixed64 f)
Minus decrement.
Definition: fixed64.hpp:38
double to_d() const
Construct from double.
Definition: fixed64.hpp:32
The namespace for this project.
Definition: abc_nodesel.hpp:20
A 64-bit fixed precision number type "implemented" as a wrapper to CCbigguy.
Definition: fixed64.hpp:21