Skip to content

Commit c62afc8

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 ffc9032 commit c62afc8

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

src/ansi-c/library/math.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -899,11 +899,14 @@ float sqrtf(float f)
899899
// number of exponent and significand bits. Thus they are
900900
// given implicitly...
901901

902+
#pragma CPROVER check push
903+
#pragma CPROVER check disable "float-overflow"
902904
float lowerSquare = lower * lower;
903905
__CPROVER_assume(__CPROVER_isnormalf(lowerSquare));
904906

905907
float upper = nextUpf(lower);
906908
float upperSquare = upper * upper; // Might be +Inf
909+
#pragma CPROVER check pop
907910

908911
// Restrict these to bound f and thus compute the possible
909912
// values for the square root. Note that the lower bound
@@ -986,11 +989,14 @@ double sqrt(double d)
986989
__CPROVER_assume(lower > 0.0);
987990
__CPROVER_assume(__CPROVER_isnormald(lower));
988991

992+
#pragma CPROVER check push
993+
#pragma CPROVER check disable "float-overflow"
989994
double lowerSquare = lower * lower;
990995
__CPROVER_assume(__CPROVER_isnormald(lowerSquare));
991996

992997
double upper = nextUp(lower);
993998
double upperSquare = upper * upper; // Might be +Inf
999+
#pragma CPROVER check pop
9941000

9951001
__CPROVER_assume(lowerSquare <= d);
9961002
__CPROVER_assume(d < upperSquare);
@@ -1060,11 +1066,14 @@ long double sqrtl(long double d)
10601066
__CPROVER_assume(lower > 0.0l);
10611067
__CPROVER_assume(__CPROVER_isnormalld(lower));
10621068

1069+
#pragma CPROVER check push
1070+
#pragma CPROVER check disable "float-overflow"
10631071
long double lowerSquare = lower * lower;
10641072
__CPROVER_assume(__CPROVER_isnormalld(lowerSquare));
10651073

10661074
long double upper = nextUpl(lower);
10671075
long double upperSquare = upper * upper; // Might be +Inf
1076+
#pragma CPROVER check pop
10681077

10691078
__CPROVER_assume(lowerSquare <= d);
10701079
__CPROVER_assume(d < upperSquare);

0 commit comments

Comments
 (0)