Skip to content

Commit 62dc70a

Browse files
authored
Merge pull request #6414 from peterschrammel/fix-fmod
Fix fmod(x, INFINITY)
2 parents e7eff1e + c4deb56 commit 62dc70a

File tree

3 files changed

+39
-2
lines changed

3 files changed

+39
-2
lines changed

regression/cbmc/fmod1/main.c

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#include <assert.h>
2+
#include <math.h>
3+
4+
void main()
5+
{
6+
// If x is +-0 and y is not zero, +-0 is returned
7+
assert(fmod(0.0, 1.0) == 0.0);
8+
assert(fmod(-0.0, 1.0) == -0.0);
9+
10+
// If x is +-oo and y is not NaN, NaN is returned and FE_INVALID is raised
11+
assert(isnan(fmod(INFINITY, 1.0)));
12+
assert(isnan(fmod(-INFINITY, 1.0)));
13+
14+
// If y is +-0 and x is not NaN, NaN is returned and FE_INVALID is raised
15+
assert(isnan(fmod(1.0, 0.0)));
16+
assert(isnan(fmod(1.0, -0.0)));
17+
18+
// If y is +-oo and x is finite, x is returned.
19+
assert(fmod(1.0, INFINITY) == 1.0);
20+
assert(fmod(1.0, -INFINITY) == 1.0);
21+
22+
// If either argument is NaN, NaN is returned
23+
assert(isnan(fmod(1.0, NAN)));
24+
assert(isnan(fmod(NAN, 1.0)));
25+
}

regression/cbmc/fmod1/test.desc

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
CORE broken-z3-smt-backend broken-smt-backend
2+
main.c
3+
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
^VERIFICATION SUCCESSFUL$
7+
--
8+
^warning: ignoring
9+
--

src/solvers/floatbv/float_utils.cpp

+5-2
Original file line numberDiff line numberDiff line change
@@ -547,8 +547,11 @@ bvt float_utilst::rem(const bvt &src1, const bvt &src2)
547547
We have some approaches that are correct but they really
548548
don't scale. */
549549

550-
// stub: do src1-(src1/src2)*src2
551-
return sub(src1, mul(div(src1, src2), src2));
550+
const unbiased_floatt unpacked2 = unpack(src2);
551+
552+
// stub: do (src2.infinity ? src1 : (src1/src2)*src2))
553+
return bv_utils.select(
554+
unpacked2.infinity, src1, sub(src1, mul(div(src1, src2), src2)));
552555
}
553556

554557
bvt float_utilst::negate(const bvt &src)

0 commit comments

Comments
 (0)