Skip to content

Commit 9c7bccc

Browse files
authored
Merge pull request #8195 from tautschnig/bugfixes/math-lib
C library: additional floating-point functions and cleanup
2 parents c81a6a6 + c56f167 commit 9c7bccc

File tree

23 files changed

+997
-28
lines changed

23 files changed

+997
-28
lines changed

Diff for: regression/cbmc-library/feraiseexcept-01/main.c

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#include <assert.h>
2+
#include <fenv.h>
3+
4+
int main()
5+
{
6+
int exceptions;
7+
feraiseexcept(exceptions);
8+
return 0;
9+
}

Diff for: regression/cbmc-library/feraiseexcept-01/test.desc

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
CORE
2+
main.c
3+
4+
^VERIFICATION FAILED$
5+
^EXIT=10$
6+
^SIGNAL=0$
7+
--
8+
^warning: ignoring

Diff for: regression/cbmc-library/fma-01/main.c

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#include <assert.h>
2+
#include <math.h>
3+
4+
int main()
5+
{
6+
double five = fma(1.0, 2.0, 3.0);
7+
assert(five > 4.99 && five < 5.01);
8+
return 0;
9+
}

Diff for: regression/cbmc-library/fma-01/test.desc

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
CORE
2+
main.c
3+
--float-overflow-check --nan-check
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
^VERIFICATION SUCCESSFUL$
7+
--
8+
^warning: ignoring

Diff for: regression/cbmc-library/fmaf-01/main.c

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#include <assert.h>
2+
#include <math.h>
3+
4+
int main()
5+
{
6+
float five = fmaf(1.0f, 2.0f, 3.0f);
7+
assert(five > 4.99f && five < 5.01f);
8+
return 0;
9+
}

Diff for: regression/cbmc-library/fmaf-01/test.desc

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
CORE
2+
main.c
3+
--float-overflow-check --nan-check
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
^VERIFICATION SUCCESSFUL$
7+
--
8+
^warning: ignoring

Diff for: regression/cbmc-library/fmal-01/main.c

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#include <assert.h>
2+
#include <math.h>
3+
4+
int main()
5+
{
6+
long double five = fmal(1.0l, 2.0l, 3.0l);
7+
assert(five > 4.99l && five < 5.01l);
8+
return 0;
9+
}

Diff for: regression/cbmc-library/fmal-01/test.desc

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
CORE
2+
main.c
3+
--float-overflow-check --nan-check
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
^VERIFICATION SUCCESSFUL$
7+
--
8+
^warning: ignoring

Diff for: regression/cbmc-library/log10-01/main.c

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#include <assert.h>
2+
#ifdef _WIN32
3+
# define _USE_MATH_DEFINES
4+
#endif
5+
#include <math.h>
6+
7+
int main()
8+
{
9+
double one = log10(10.0);
10+
assert(one > 0.978 && one < 1.005);
11+
return 0;
12+
}

Diff for: regression/cbmc-library/log10-01/test.desc

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
CORE
2+
main.c
3+
--float-overflow-check --nan-check
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
^VERIFICATION SUCCESSFUL$
7+
--
8+
^warning: ignoring

Diff for: regression/cbmc-library/log10f-01/main.c

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#include <assert.h>
2+
#ifdef _WIN32
3+
# define _USE_MATH_DEFINES
4+
#endif
5+
#include <math.h>
6+
7+
int main()
8+
{
9+
float one = log10f(10.0f);
10+
assert(one > 0.978f && one < 1.005f);
11+
return 0;
12+
}

Diff for: regression/cbmc-library/log10f-01/test.desc

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
CORE
2+
main.c
3+
--float-overflow-check --nan-check
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
^VERIFICATION SUCCESSFUL$
7+
--
8+
^warning: ignoring

Diff for: regression/cbmc-library/log10l-01/main.c

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#include <assert.h>
2+
#ifdef _WIN32
3+
# define _USE_MATH_DEFINES
4+
#endif
5+
#include <math.h>
6+
7+
int main()
8+
{
9+
long double one = log10l(10.0l);
10+
assert(one > 0.978l && one < 1.005l);
11+
return 0;
12+
}

Diff for: regression/cbmc-library/log10l-01/test.desc

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
CORE
2+
main.c
3+
--float-overflow-check --nan-check
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
^VERIFICATION SUCCESSFUL$
7+
--
8+
^warning: ignoring

Diff for: regression/cbmc-library/log2-01/main.c

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#include <assert.h>
2+
#ifdef _WIN32
3+
# define _USE_MATH_DEFINES
4+
#endif
5+
#include <math.h>
6+
7+
int main()
8+
{
9+
double one = log2(2.0);
10+
assert(one > 0.999 && one < 1.087);
11+
return 0;
12+
}

Diff for: regression/cbmc-library/log2-01/test.desc

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
CORE
2+
main.c
3+
--float-overflow-check --nan-check
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
^VERIFICATION SUCCESSFUL$
7+
--
8+
^warning: ignoring

Diff for: regression/cbmc-library/log2f-01/main.c

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#include <assert.h>
2+
#ifdef _WIN32
3+
# define _USE_MATH_DEFINES
4+
#endif
5+
#include <math.h>
6+
7+
int main()
8+
{
9+
float one = log2f(2.0f);
10+
assert(one > 0.999f && one < 1.087f);
11+
return 0;
12+
}

Diff for: regression/cbmc-library/log2f-01/test.desc

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
CORE
2+
main.c
3+
--float-overflow-check --nan-check
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
^VERIFICATION SUCCESSFUL$
7+
--
8+
^warning: ignoring

Diff for: regression/cbmc-library/log2l-01/main.c

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#include <assert.h>
2+
#ifdef _WIN32
3+
# define _USE_MATH_DEFINES
4+
#endif
5+
#include <math.h>
6+
7+
int main()
8+
{
9+
long double one = log2l(2.0l);
10+
assert(one > 0.999l && one < 1.087l);
11+
return 0;
12+
}

Diff for: regression/cbmc-library/log2l-01/test.desc

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
CORE
2+
main.c
3+
--float-overflow-check --nan-check
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
^VERIFICATION SUCCESSFUL$
7+
--
8+
^warning: ignoring

Diff for: 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
}

Diff for: src/ansi-c/library/fenv.c

+9
Original file line numberDiff line numberDiff line change
@@ -40,3 +40,12 @@ __CPROVER_HIDE:;
4040
0;
4141
return 0; // we never fail
4242
}
43+
44+
/* FUNCTION: feraiseexcept */
45+
46+
int feraiseexcept(int excepts)
47+
{
48+
__CPROVER_HIDE:;
49+
__CPROVER_assert(excepts == 0, "floating-point exception");
50+
return 0; // we never fail
51+
}

0 commit comments

Comments
 (0)