CBMC
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
float_approximation.cpp
Go to the documentation of this file.
1/*******************************************************************\
2
3Module:
4
5Author: Daniel Kroening, kroening@kroening.com
6
7\*******************************************************************/
8
10
14
16{
17 // this thing is quadratic!
18 // returns 'zero' if fraction is zero
19 bvt new_fraction=prop.new_variables(fraction.size());
20 bvt new_exponent=prop.new_variables(exponent.size());
21
22 // i is the shift distance
23 for(unsigned i=0; i<fraction.size(); i++)
24 {
25 bvt equal;
26
27 // the bits above need to be zero
28 for(unsigned j=0; j<i; j++)
29 equal.push_back(
30 !fraction[fraction.size()-1-j]);
31
32 // this one needs to be one
33 equal.push_back(fraction[fraction.size()-1-i]);
34
35 // iff all of that holds, we shift here!
36 literalt shift=prop.land(equal);
37
38 // build shifted value
42 else
45
47
48 // build new exponent
50 bv_utils.build_constant(-static_cast<int>(i), exponent.size());
53 }
54
55 // fraction all zero? it stays zero
56 // the exponent is undefined in that case
59 zero_fraction.resize(fraction.size(), const_literal(false));
61
62 fraction=new_fraction;
63 exponent=new_exponent;
64}
65
67 const bvt &src, unsigned dist)
68{
69 bvt result;
70 result.resize(src.size());
71
72 for(unsigned i=0; i<src.size(); i++)
73 {
74 literalt l;
75
76 l=(dist<=i?src[i-dist]:prop.new_variable());
77 result[i]=l;
78 }
79
80 return result;
81}
ait supplies three of the four components needed: an abstract interpreter (in this case handling func...
Definition ai.h:562
bvt add(const bvt &op0, const bvt &op1)
Definition bv_utils.h:66
static bvt build_constant(const mp_integer &i, std::size_t width)
Definition bv_utils.cpp:14
literalt is_zero(const bvt &op)
Definition bv_utils.h:143
void cond_implies_equal(literalt cond, const bvt &a, const bvt &b)
static bvt shift(const bvt &op, const shiftt shift, std::size_t distance)
Definition bv_utils.cpp:537
bvt overapproximating_left_shift(const bvt &src, unsigned dist)
virtual void normalization_shift(bvt &fraction, bvt &exponent)
normalize fraction/exponent pair returns 'zero' if fraction is zero
bv_utilst bv_utils
virtual literalt land(literalt a, literalt b)=0
virtual bvt new_variables(std::size_t width)
generates a bitvector of given width with new variables
Definition prop.cpp:30
virtual literalt new_variable()=0
Floating Point with under/over-approximation.
std::vector< literalt > bvt
Definition literal.h:201
literalt const_literal(bool value)
Definition literal.h:188