ESBMC
Efficient SMT-based Context-Bounded Model Checker
Loading...
Searching...
No Matches
fixedbv.h
Go to the documentation of this file.
1#ifndef CPROVER_FIXEDBV_UTIL_H
2#define CPROVER_FIXEDBV_UTIL_H
3
5#include <irep2/irep2_type.h>
9
11{
12public:
14
16 {
17 }
18
19 fixedbv_spect(unsigned _width, unsigned _integer_bits)
20 : integer_bits(_integer_bits), width(_width)
21 {
22 assert(width >= integer_bits);
23 }
24
25 fixedbv_spect(const fixedbv_typet &type);
26 fixedbv_spect(const fixedbv_type2t &type);
27
28 inline unsigned get_fraction_bits() const
29 {
30 return width - integer_bits;
31 }
32
33 /* that's a fixedbv_type2t */
34 type2tc get_type() const;
35};
36
38{
39public:
41
42 fixedbvt();
43 fixedbvt(const fixedbv_spect &s);
44
45 explicit fixedbvt(const constant_exprt &expr);
46
47 void from_integer(const BigInt &i);
48 BigInt to_integer() const; // this rounds to zero
49 void from_expr(const constant_exprt &expr);
50 constant_exprt to_expr() const;
51 void round(const fixedbv_spect &dest_spec);
52
53 std::string to_ansi_c_string() const
54 {
55 return format(format_spect());
56 }
57
58 std::string format(const format_spect &format_spec) const;
59
60 bool operator==(int i) const;
61 bool is_zero() const
62 {
63 return v == 0;
64 }
65
66 bool is_negative() const
67 {
68 return v.is_negative();
69 }
70
71 bool get_sign() const
72 {
73 return v.is_negative();
74 }
75
76 // Never true
77 bool is_NaN() const
78 {
79 return false;
80 }
81
82 // Never true
83 bool is_infinity() const
84 {
85 return false;
86 }
87
88 // Always true
89 bool is_finite() const
90 {
91 return true;
92 }
93
94 // Always true?
95 bool is_normal() const
96 {
97 return true;
98 }
99
100 void negate();
101
107
109
110 friend bool operator<(const fixedbvt &a, const fixedbvt &b)
111 {
112 return a.v < b.v;
113 }
114 friend bool operator<=(const fixedbvt &a, const fixedbvt &b)
115 {
116 return a.v <= b.v;
117 }
118 friend bool operator>(const fixedbvt &a, const fixedbvt &b)
119 {
120 return a.v > b.v;
121 }
122 friend bool operator>=(const fixedbvt &a, const fixedbvt &b)
123 {
124 return a.v >= b.v;
125 }
126 friend bool operator==(const fixedbvt &a, const fixedbvt &b)
127 {
128 return a.v == b.v;
129 }
130 friend bool operator!=(const fixedbvt &a, const fixedbvt &b)
131 {
132 return a.v != b.v;
133 }
134
135 friend bool operator>(const fixedbvt &a, int i);
136 friend bool operator<(const fixedbvt &a, int i);
137 friend bool operator>=(const fixedbvt &a, int i);
138 friend bool operator<=(const fixedbvt &a, int i);
139
140 const BigInt &get_value() const
141 {
142 return v;
143 }
144 void set_value(const BigInt &_v)
145 {
146 v = _v;
147 }
148
149protected:
150 // negative values stored as such
152};
153
154bool operator<(const fixedbvt &a, const fixedbvt &b);
155bool operator<=(const fixedbvt &a, const fixedbvt &b);
156bool operator>(const fixedbvt &a, const fixedbvt &b);
157bool operator>=(const fixedbvt &a, const fixedbvt &b);
158bool operator==(const fixedbvt &a, const fixedbvt &b);
159bool operator!=(const fixedbvt &a, const fixedbvt &b);
160
161#endif
Definition bigint.hh:58
Definition std_expr.h:1082
Definition fixedbv.h:11
unsigned integer_bits
Definition fixedbv.h:13
type2tc get_type() const
Definition fixedbv.cpp:17
unsigned get_fraction_bits() const
Definition fixedbv.h:28
fixedbv_spect(unsigned _width, unsigned _integer_bits)
Definition fixedbv.h:19
fixedbv_spect()
Definition fixedbv.h:15
unsigned width
Definition fixedbv.h:13
Fixed bitvector type.
Definition irep2_type.h:595
Definition std_types.h:600
Definition fixedbv.h:38
fixedbv_spect spec
Definition fixedbv.h:40
friend bool operator==(const fixedbvt &a, const fixedbvt &b)
Definition fixedbv.h:126
fixedbvt()
Definition fixedbv.cpp:22
friend bool operator>(const fixedbvt &a, const fixedbvt &b)
Definition fixedbv.h:118
void from_expr(const constant_exprt &expr)
Definition fixedbv.cpp:35
bool is_finite() const
Definition fixedbv.h:89
void negate()
Definition fixedbv.cpp:116
friend bool operator<(const fixedbvt &a, const fixedbvt &b)
Definition fixedbv.h:110
void set_value(const BigInt &_v)
Definition fixedbv.h:144
bool operator==(int i) const
Definition fixedbv.cpp:156
bool is_NaN() const
Definition fixedbv.h:77
friend bool operator>=(const fixedbvt &a, const fixedbvt &b)
Definition fixedbv.h:122
fixedbvt & operator+=(const fixedbvt &other)
Definition fixedbv.cpp:203
fixedbvt & operator*=(const fixedbvt &other)
Definition fixedbv.cpp:121
friend bool operator<=(const fixedbvt &a, const fixedbvt &b)
Definition fixedbv.h:114
void round(const fixedbv_spect &dest_spec)
Definition fixedbv.cpp:63
friend bool operator!=(const fixedbvt &a, const fixedbvt &b)
Definition fixedbv.h:130
std::string format(const format_spect &format_spec) const
Definition fixedbv.cpp:161
void from_integer(const BigInt &i)
Definition fixedbv.cpp:41
bool get_sign() const
Definition fixedbv.h:71
fixedbvt & operator-()
Definition fixedbv.cpp:223
BigInt v
Definition fixedbv.h:151
std::string to_ansi_c_string() const
Definition fixedbv.h:53
fixedbvt & operator/=(const fixedbvt &other)
Definition fixedbv.cpp:135
BigInt to_integer() const
Definition fixedbv.cpp:46
bool is_negative() const
Definition fixedbv.h:66
bool is_normal() const
Definition fixedbv.h:95
fixedbvt & operator-=(const fixedbvt &other)
Definition fixedbv.cpp:213
bool is_zero() const
Definition fixedbv.h:61
const BigInt & get_value() const
Definition fixedbv.h:140
fixedbvt & operator%=(const fixedbvt &other)
Definition fixedbv.cpp:143
bool is_infinity() const
Definition fixedbv.h:83
constant_exprt to_expr() const
Definition fixedbv.cpp:52
Definition format_spec.h:5
@ other
Definition converter_compare.cpp:887
bool operator==(const fixedbvt &a, const fixedbvt &b)
Definition fixedbv.h:126
bool operator>(const fixedbvt &a, const fixedbvt &b)
Definition fixedbv.h:118
bool operator<(const fixedbvt &a, const fixedbvt &b)
Definition fixedbv.h:110
bool operator>=(const fixedbvt &a, const fixedbvt &b)
Definition fixedbv.h:122
bool operator<=(const fixedbvt &a, const fixedbvt &b)
Definition fixedbv.h:114
bool operator!=(const fixedbvt &a, const fixedbvt &b)
Definition fixedbv.h:130
irep_container< type2t > type2tc
Definition irep2.h:430