Skip to content

Commit 7bd7f16

Browse files
author
kroening
committed
fix for floating-point division for the case of normal / subnormal
1 parent c04aa66 commit 7bd7f16

File tree

3 files changed

+34
-2
lines changed

3 files changed

+34
-2
lines changed

regression/cbmc/Float-div2/main.c

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#include <assert.h>
2+
#include <math.h>
3+
4+
float nondet_float (void);
5+
6+
int main (void) {
7+
float f = nondet_float();
8+
// Everything in this range hits the bug
9+
__CPROVER_assume(f < +INFINITY);
10+
__CPROVER_assume(f >= 0x1.0p+107f);
11+
__CPROVER_assume(f > 0.0f);
12+
13+
float g = nondet_float();
14+
__CPROVER_assume(g <= 0x1.0p-149f);
15+
__CPROVER_assume(g > 0.0f);
16+
17+
// exponent is >= 107 - -127 = 234 = 255 - 21
18+
float div = f / g;
19+
20+
assert(!(div == 0.0));
21+
22+
return 1;
23+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
CORE
2+
main.c
3+
--floatbv
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
^VERIFICATION SUCCESSFUL$
7+
--
8+
^warning: ignoring

src/solvers/floatbv/float_utils.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -632,8 +632,9 @@ bvt float_utilst::div(const bvt &src1, const bvt &src2)
632632

633633
// We will subtract the exponents;
634634
// to account for overflow, we add a bit.
635-
const bvt exponent1=bv_utils.sign_extension(unpacked1.exponent, unpacked1.exponent.size()+1);
636-
const bvt exponent2=bv_utils.sign_extension(unpacked2.exponent, unpacked2.exponent.size()+1);
635+
// we add a second bit for the adjust by extra fraction bits
636+
const bvt exponent1=bv_utils.sign_extension(unpacked1.exponent, unpacked1.exponent.size()+2);
637+
const bvt exponent2=bv_utils.sign_extension(unpacked2.exponent, unpacked2.exponent.size()+2);
637638

638639
// subtract exponents
639640
bvt added_exponent=bv_utils.sub(exponent1, exponent2);

0 commit comments

Comments
 (0)