@@ -30,6 +30,10 @@ class rational {
30
30
31
31
static synch_mpq_manager & m () { return *g_mpq_manager; }
32
32
33
+ void display_hex (std::ostream & out, unsigned num_bits) const { SASSERT (is_int ()); m ().display_hex (out, m_val.numerator (), num_bits); }
34
+
35
+ void display_bin (std::ostream& out, unsigned num_bits) const { SASSERT (is_int ()); m ().display_bin (out, m_val.numerator (), num_bits); }
36
+
33
37
public:
34
38
static void initialize ();
35
39
static void finalize ();
@@ -96,9 +100,33 @@ class rational {
96
100
97
101
void display_smt2 (std::ostream & out) const { return m ().display_smt2 (out, m_val, false ); }
98
102
99
- void display_hex (std::ostream & out, unsigned num_bits) const { SASSERT (is_int ()); return m ().display_hex (out, m_val.numerator (), num_bits); }
100
103
101
- void display_bin (std::ostream & out, unsigned num_bits) const { SASSERT (is_int ()); return m ().display_bin (out, m_val.numerator (), num_bits); }
104
+ struct as_hex_wrapper {
105
+ rational const & r;
106
+ unsigned bw;
107
+ };
108
+
109
+ as_hex_wrapper as_hex (unsigned bw) const { return as_hex_wrapper{*this , bw}; }
110
+
111
+ friend inline std::ostream& operator <<(std::ostream& out, as_hex_wrapper const & ab) {
112
+ ab.r .display_hex (out, ab.bw );
113
+ return out;
114
+ }
115
+
116
+
117
+
118
+ struct as_bin_wrapper {
119
+ rational const & r;
120
+ unsigned bw;
121
+ };
122
+
123
+ as_bin_wrapper as_bin (unsigned bw) const { return as_bin_wrapper{*this , bw}; }
124
+
125
+ friend inline std::ostream& operator <<(std::ostream& out, as_bin_wrapper const & ab) {
126
+ ab.r .display_bin (out, ab.bw );
127
+ return out;
128
+ }
129
+
102
130
103
131
bool is_uint64 () const { return m ().is_uint64 (m_val); }
104
132
0 commit comments