Skip to content

Commit bd29015

Browse files
authored
Merge pull request #8968 from diffblue/bit-to-fp1
float_utils: normalization shift for very short fractions
2 parents 453c863 + 425cbfa commit bd29015

3 files changed

Lines changed: 30 additions & 2 deletions

File tree

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
CORE
2+
bit-to-fp1.smt2
3+
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
^unsat$
7+
--
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
;
2+
; convert (_ bv1 1) to double precision FP,
3+
; and check whether that is equal to 1.0.
4+
;
5+
(define-fun B0 () Bool (=
6+
((_ to_fp_unsigned 11 53) roundNearestTiesToAway (_ bv1 1))
7+
(fp #b0 #b01111111111 #b0000000000000000000000000000000000000000000000000000)))
8+
9+
(assert (not B0))
10+
11+
; expected to be UNSAT, i.e., they are equal
12+
(check-sat)
13+
14+
(exit)

‎src/solvers/floatbv/float_utils.cpp‎

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -917,7 +917,7 @@ void float_utilst::normalization_shift(bvt &fraction, bvt &exponent)
917917
literalt shift=prop.land(equal);
918918

919919
// build shifted value
920-
bvt shifted_fraction=bv_utils.shift(fraction, bv_utilst::LEFT, i);
920+
bvt shifted_fraction=bv_utils.shift(fraction, bv_utilst::shiftt::SHIFT_LEFT, i);
921921
bv_utils.cond_implies_equal(shift, shifted_fraction, new_fraction);
922922

923923
// build new exponent
@@ -950,11 +950,18 @@ void float_utilst::normalization_shift(bvt &fraction, bvt &exponent)
950950

951951
bvt exponent_delta=bv_utils.zeros(exponent.size());
952952

953+
// Fraction smaller than the max distance? Pad up with zeros.
954+
std::size_t max_distance = 1 << (depth - 1);
955+
956+
if(fraction.size() < max_distance)
957+
fraction = bv_utils.zero_extension(fraction, max_distance);
958+
953959
for(int d=depth-1; d>=0; d--)
954960
{
955961
std::size_t distance=(1<<d);
962+
956963
INVARIANT(
957-
fraction.size() > distance, "fraction must be larger than distance");
964+
fraction.size() >= distance, "fraction must be larger or equal distance");
958965

959966
// check if first 'distance'-many bits are zeros
960967
const bvt prefix=bv_utils.extract_msb(fraction, distance);

0 commit comments

Comments
 (0)