Skip to content

Commit 7b78a86

Browse files
committed
FP: improve error message and add test for it.
1 parent 2ec4fce commit 7b78a86

File tree

2 files changed

+23
-3
lines changed

2 files changed

+23
-3
lines changed

src/org/sosy_lab/java_smt/basicimpl/AbstractFloatingPointFormulaManager.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -266,9 +266,8 @@ public FloatingPointFormula fromIeeeBitvector(
266266
MoreStrings.lazyString(
267267
() ->
268268
String.format(
269-
"The total size of the used FloatingPointType %s has to match the size of "
270-
+ "the bitvector argument %s",
271-
pTargetType.getTotalSize(), bvType.getSize())));
269+
"The total size %s of type %s has to match the size %s of type %s.",
270+
pTargetType.getTotalSize(), pTargetType, bvType.getSize(), bvType)));
272271
return wrap(fromIeeeBitvectorImpl(extractInfo(pNumber), pTargetType));
273272
}
274273

src/org/sosy_lab/java_smt/test/FloatingPointFormulaManagerTest.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1098,6 +1098,27 @@ public void checkString2FpConversion64() throws SolverException, InterruptedExce
10981098
fpmgr.makeNumber(Double.toString(pDouble), doublePrecType)));
10991099
}
11001100

1101+
@Test
1102+
public void checkErrorOnInvalidSize_IeeeBv2FpConversion() {
1103+
BitvectorFormula bv = bvmgr.makeBitvector(9, 123);
1104+
1105+
var exSingle =
1106+
assertThrows(
1107+
IllegalArgumentException.class, () -> fpmgr.fromIeeeBitvector(bv, singlePrecType));
1108+
assertThat(exSingle.getMessage())
1109+
.contains(
1110+
"The total size 32 of type FloatingPoint<exp=8,mant=23> "
1111+
+ "has to match the size 9 of type Bitvector<9>.");
1112+
1113+
var exDouble =
1114+
assertThrows(
1115+
IllegalArgumentException.class, () -> fpmgr.fromIeeeBitvector(bv, doublePrecType));
1116+
assertThat(exDouble.getMessage())
1117+
.contains(
1118+
"The total size 64 of type FloatingPoint<exp=11,mant=52> "
1119+
+ "has to match the size 9 of type Bitvector<9>.");
1120+
}
1121+
11011122
@Test
11021123
public void checkIeeeBv2FpConversion32() throws SolverException, InterruptedException {
11031124
proveForAll(

0 commit comments

Comments
 (0)