Skip to content

Commit 1bc9833

Browse files
committed
C library: do not flag division-by-zero when building NaN
We construct NaN (and Inf) by dividing by zero, which is a standards-compliant way in that Nan (Inf) is the correct result for these cases. Do not flag these operations as division-by-zero, which the user would not expect.
1 parent 7329ada commit 1bc9833

File tree

2 files changed

+130
-0
lines changed
  • regression/cbmc-library/pow-01
  • src/ansi-c/library

2 files changed

+130
-0
lines changed

regression/cbmc-library/pow-01/main.c

+10
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,19 @@
11
#include <assert.h>
2+
#include <float.h>
23
#include <math.h>
34

45
int main()
56
{
67
double four = pow(2.0, 2.0);
78
assert(four > 3.999 && four < 4.345);
9+
10+
double x;
11+
__CPROVER_assume(isnormal(x));
12+
double limit = 1 << 15;
13+
__CPROVER_assume(x > -limit && x < limit);
14+
__CPROVER_assume(x > FLT_MIN || x < -FLT_MIN);
15+
double sq = pow(x, 2.0);
16+
assert(sq >= 0.0);
17+
818
return 0;
919
}

0 commit comments

Comments
 (0)