Skip to content

Commit d1341af

Browse files
author
Daniel Kroening
committed
conversion of floatbv constants to fixedbv constants
1 parent 9908b6e commit d1341af

File tree

9 files changed

+29
-12
lines changed

9 files changed

+29
-12
lines changed

regression/cbmc/Fixedbv1/main.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#include <assert.h>
2+
13
int main() {
24
__CPROVER_fixedbv[64][32] x;
35
int y;

regression/cbmc/Fixedbv1/test.desc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
KNOWNBUG
1+
CORE
22
main.c
33

44
^EXIT=0$

regression/cbmc/Fixedbv2/main.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1+
#include <assert.h>
2+
13
main() {
24
__CPROVER_fixedbv[32][16] a;
35
__CPROVER_fixedbv[64][32] b;
46

57
a=1.25L;
6-
assert(a==1.25);
8+
assert(a==(__CPROVER_fixedbv[32][16])1.25);
79

810
b=1.250;
9-
assert(b==1.25);
11+
assert(b==(__CPROVER_fixedbv[64][32])1.25);
1012
}

regression/cbmc/Fixedbv2/test.desc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
KNOWNBUG
1+
CORE
22
main.c
33

44
^EXIT=0$

regression/cbmc/Fixedbv3/main.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#include <assert.h>
2+
13
int nondet_int();
24

35
__CPROVER_fixedbv[64][32] d = 0.0;
@@ -20,5 +22,5 @@ int main()
2022

2123
d += (x > 3);
2224

23-
assert(d == 2.0);
25+
assert(d == (__CPROVER_fixedbv[64][32])2.0);
2426
}

regression/cbmc/Fixedbv3/test.desc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
KNOWNBUG
1+
CORE
22
main.c
33

44
^EXIT=0$

regression/cbmc/Fixedbv5/main.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ int main()
33
typedef __CPROVER_fixedbv[32][16] ft;
44
ft a, b;
55

6-
__CPROVER_assume(a==1 || a==(ft)0.5 || a==2 || a==3 || a==(ft)0.1);
6+
__CPROVER_assume(a==1 || a==(ft)0.5 || a==2 || a==3 || a==(ft)0.25);
77
b=a;
88
a/=2;
99
a*=2;

regression/cbmc/Fixedbv5/test.desc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
KNOWNBUG
1+
CORE
22
main.c
33

44
^EXIT=0$

src/util/simplify_expr.cpp

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -657,14 +657,14 @@ bool simplify_exprt::simplify_typecast(exprt &expr)
657657
if(expr_type_id==ID_unsignedbv ||
658658
expr_type_id==ID_signedbv)
659659
{
660-
// cast from float to int
660+
// cast from fixedbv to int
661661
fixedbvt f(to_constant_expr(expr.op0()));
662662
expr=from_integer(f.to_integer(), expr_type);
663663
return false;
664664
}
665665
else if(expr_type_id==ID_fixedbv)
666666
{
667-
// float to double or double to float
667+
// fixedbv to fixedbv
668668
fixedbvt f(to_constant_expr(expr.op0()));
669669
f.round(to_fixedbv_type(expr_type));
670670
expr=f.to_expr();
@@ -673,22 +673,33 @@ bool simplify_exprt::simplify_typecast(exprt &expr)
673673
}
674674
else if(op_type_id==ID_floatbv)
675675
{
676+
ieee_floatt f(to_constant_expr(expr.op0()));
677+
676678
if(expr_type_id==ID_unsignedbv ||
677679
expr_type_id==ID_signedbv)
678680
{
679681
// cast from float to int
680-
ieee_floatt f(to_constant_expr(expr.op0()));
681682
expr=from_integer(f.to_integer(), expr_type);
682683
return false;
683684
}
684685
else if(expr_type_id==ID_floatbv)
685686
{
686687
// float to double or double to float
687-
ieee_floatt f(to_constant_expr(expr.op0()));
688688
f.change_spec(to_floatbv_type(expr_type));
689689
expr=f.to_expr();
690690
return false;
691691
}
692+
else if(expr_type_id==ID_fixedbv)
693+
{
694+
fixedbvt fixedbv;
695+
fixedbv.spec=fixedbv_spect(to_fixedbv_type(expr_type));
696+
ieee_floatt factor(f.spec);
697+
factor.from_integer(power(2, fixedbv.spec.get_fraction_bits()));
698+
f*=factor;
699+
fixedbv.set_value(f.to_integer());
700+
expr=fixedbv.to_expr();
701+
return false;
702+
}
692703
}
693704
else if(op_type_id==ID_bv)
694705
{

0 commit comments

Comments
 (0)