@@ -55,6 +55,7 @@ public class FloatingPointFormulaManagerTest
5555 private FloatingPointFormula negInf ;
5656 private FloatingPointFormula zero ;
5757 private FloatingPointFormula one ;
58+ private FloatingPointFormula negZero ;
5859
5960 @ Before
6061 public void init () {
@@ -66,6 +67,7 @@ public void init() {
6667 posInf = fpmgr .makePlusInfinity (singlePrecType );
6768 negInf = fpmgr .makeMinusInfinity (singlePrecType );
6869 zero = fpmgr .makeNumber (0.0 , singlePrecType );
70+ negZero = fpmgr .makeNumber (-0.0 , singlePrecType );
6971 one = fpmgr .makeNumber (1.0 , singlePrecType );
7072 }
7173
@@ -131,8 +133,7 @@ public void parser() throws SolverException, InterruptedException {
131133 public void negativeZeroDivision () throws SolverException , InterruptedException {
132134 BooleanFormula formula =
133135 fpmgr .equalWithFPSemantics (
134- fpmgr .divide (
135- one , fpmgr .makeNumber (-0.0 , singlePrecType ), FloatingPointRoundingMode .TOWARD_ZERO ),
136+ fpmgr .divide (one , negZero , FloatingPointRoundingMode .TOWARD_ZERO ),
136137 fpmgr .makeMinusInfinity (singlePrecType ));
137138 assertThatFormula (formula ).isSatisfiable ();
138139 assertThatFormula (bmgr .not (formula )).isUnsatisfiable ();
@@ -267,8 +268,8 @@ public void specialValueFunctions() throws SolverException, InterruptedException
267268 assertThatFormula (fpmgr .isSubnormal (zero )).isUnsatisfiable ();
268269 assertThatFormula (fpmgr .isSubnormal (zero )).isUnsatisfiable ();
269270
270- FloatingPointFormula negZero = fpmgr .makeNumber (-0.0 , singlePrecType );
271271 assertThatFormula (fpmgr .isZero (negZero )).isTautological ();
272+ assertThatFormula (fpmgr .equalWithFPSemantics (zero , negZero )).isTautological ();
272273 assertThatFormula (fpmgr .isSubnormal (negZero )).isUnsatisfiable ();
273274 assertThatFormula (fpmgr .isSubnormal (negZero )).isUnsatisfiable ();
274275
@@ -1056,4 +1057,27 @@ public void fpFrom64BitPattern() throws SolverException, InterruptedException {
10561057 assertEqualsAsFormula (fpFromBv , fp );
10571058 }
10581059 }
1060+
1061+ @ Test
1062+ public void fpFromNumberIntoTooNarrowType () throws SolverException , InterruptedException {
1063+ // near zero rounds to zero, if precision is too narrow
1064+ for (double nearZero : new double [] {Double .MIN_VALUE , Float .MIN_VALUE / 2d }) {
1065+ assertThatFormula (
1066+ fpmgr .equalWithFPSemantics (zero , fpmgr .makeNumber (nearZero , singlePrecType )))
1067+ .isTautological ();
1068+ assertThatFormula (
1069+ fpmgr .equalWithFPSemantics (negZero , fpmgr .makeNumber (-nearZero , singlePrecType )))
1070+ .isTautological ();
1071+ }
1072+
1073+ // near infinity rounds to infinity, if precision is too narrow
1074+ for (double nearInf : new double [] {Double .MAX_VALUE , Float .MAX_VALUE * 2d }) {
1075+ assertThatFormula (
1076+ fpmgr .equalWithFPSemantics (posInf , fpmgr .makeNumber (nearInf , singlePrecType )))
1077+ .isTautological ();
1078+ assertThatFormula (
1079+ fpmgr .equalWithFPSemantics (negInf , fpmgr .makeNumber (-nearInf , singlePrecType )))
1080+ .isTautological ();
1081+ }
1082+ }
10591083}
0 commit comments