Skip to content

Commit 085068c

Browse files
committed
C library: do not report overflow in sqrt
We guess upper and lower bounds and check them for infinity afterwards. Those multiplications should not be flagged by auto-generated assertions.
1 parent 10009e7 commit 085068c

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

src/ansi-c/library/math.c

+9
Original file line numberDiff line numberDiff line change
@@ -905,11 +905,14 @@ float sqrtf(float f)
905905
// number of exponent and significand bits. Thus they are
906906
// given implicitly...
907907

908+
#pragma CPROVER check push
909+
#pragma CPROVER check disable "float-overflow"
908910
float lowerSquare = lower * lower;
909911
__CPROVER_assume(__CPROVER_isnormalf(lowerSquare));
910912

911913
float upper = nextUpf(lower);
912914
float upperSquare = upper * upper; // Might be +Inf
915+
#pragma CPROVER check pop
913916

914917
// Restrict these to bound f and thus compute the possible
915918
// values for the square root. Note that the lower bound
@@ -992,11 +995,14 @@ double sqrt(double d)
992995
__CPROVER_assume(lower > 0.0);
993996
__CPROVER_assume(__CPROVER_isnormald(lower));
994997

998+
#pragma CPROVER check push
999+
#pragma CPROVER check disable "float-overflow"
9951000
double lowerSquare = lower * lower;
9961001
__CPROVER_assume(__CPROVER_isnormald(lowerSquare));
9971002

9981003
double upper = nextUp(lower);
9991004
double upperSquare = upper * upper; // Might be +Inf
1005+
#pragma CPROVER check pop
10001006

10011007
__CPROVER_assume(lowerSquare <= d);
10021008
__CPROVER_assume(d < upperSquare);
@@ -1066,11 +1072,14 @@ long double sqrtl(long double d)
10661072
__CPROVER_assume(lower > 0.0l);
10671073
__CPROVER_assume(__CPROVER_isnormalld(lower));
10681074

1075+
#pragma CPROVER check push
1076+
#pragma CPROVER check disable "float-overflow"
10691077
long double lowerSquare = lower * lower;
10701078
__CPROVER_assume(__CPROVER_isnormalld(lowerSquare));
10711079

10721080
long double upper = nextUpl(lower);
10731081
long double upperSquare = upper * upper; // Might be +Inf
1082+
#pragma CPROVER check pop
10741083

10751084
__CPROVER_assume(lowerSquare <= d);
10761085
__CPROVER_assume(d < upperSquare);

0 commit comments

Comments
 (0)