Skip to content

Commit

Permalink
C library: do not flag division-by-zero when building NaN
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
tautschnig committed Feb 7, 2024
1 parent 6153505 commit 406a39a
Show file tree
Hide file tree
Showing 2 changed files with 124 additions and 0 deletions.
10 changes: 10 additions & 0 deletions regression/cbmc-library/pow-01/main.c
Original file line number Diff line number Diff line change
@@ -1,9 +1,19 @@
#include <assert.h>
#include <float.h>
#include <math.h>

int main()
{
double four = pow(2.0, 2.0);
assert(four > 3.999 && four < 4.345);

double x;
__CPROVER_assume(isnormal(x));
double limit = 1 << 15;
__CPROVER_assume(x > -limit && x < limit);
__CPROVER_assume(x > FLT_MIN || x < -FLT_MIN);
double sq = pow(x, 2.0);
assert(sq >= 0.0);

return 0;
}
Loading

0 comments on commit 406a39a

Please sign in to comment.