Skip to content

Commit f682d2a

Browse files
committed
add more tests for new FP construction.
1 parent 509604b commit f682d2a

File tree

1 file changed

+39
-10
lines changed

1 file changed

+39
-10
lines changed

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

Lines changed: 39 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -777,12 +777,16 @@ private List<Float> getListOfFloats() {
777777
Float.MAX_VALUE,
778778
Float.POSITIVE_INFINITY,
779779
Float.NEGATIVE_INFINITY,
780-
0.0f // , -0.0f // MathSat5 fails for NEGATIVE_ZERO
781-
);
780+
0.0f, // , -0.0f // MathSat5 fails for NEGATIVE_ZERO
781+
1f,
782+
-1f,
783+
2f,
784+
-2f);
782785

783786
for (int i = 1; i < 20; i++) {
784787
for (int j = 1; j < 20; j++) {
785788
flts.add((float) (i * Math.pow(10, j)));
789+
flts.add((float) (-i * Math.pow(10, j)));
786790
}
787791
}
788792

@@ -806,12 +810,16 @@ private List<Double> getListOfDoubles() {
806810
Double.MAX_VALUE,
807811
Double.POSITIVE_INFINITY,
808812
Double.NEGATIVE_INFINITY,
809-
0.0 // , -0.0 // MathSat5 fails for NEGATIVE_ZERO
810-
);
813+
0.0, // , -0.0 // MathSat5 fails for NEGATIVE_ZERO
814+
1d,
815+
-1d,
816+
2d,
817+
-2d);
811818

812819
for (int i = 1; i < 20; i++) {
813820
for (int j = 1; j < 20; j++) {
814821
dbls.add(i * Math.pow(10, j));
822+
dbls.add(-i * Math.pow(10, j));
815823
}
816824
}
817825

@@ -952,11 +960,32 @@ public void failOnInvalidString() {
952960
}
953961

954962
@Test
955-
public void fpFromBitPattern() throws SolverException, InterruptedException {
956-
final FloatingPointFormula expr1 = fpmgr.makeNumber(-0.1, singlePrecType);
957-
final FloatingPointFormula expr2 =
958-
fpmgr.makeNumber(
959-
BigInteger.valueOf(123), BigInteger.valueOf(5033165), true, singlePrecType);
960-
assertThatFormula(fpmgr.assignment(expr1, expr2)).isTautological();
963+
public void fpFrom32BitPattern() throws SolverException, InterruptedException {
964+
for (float f : getListOfFloats()) {
965+
int bits = Float.floatToRawIntBits(f);
966+
int exponent = (bits >>> 23) & 0xFF;
967+
int mantissa = bits & 0x7FFFFF;
968+
boolean sign = bits < 0; // equal to: (bits >>> 31) & 0x1
969+
final FloatingPointFormula fpFromBv =
970+
fpmgr.makeNumber(
971+
BigInteger.valueOf(exponent), BigInteger.valueOf(mantissa), sign, singlePrecType);
972+
final FloatingPointFormula fp = fpmgr.makeNumber(f, singlePrecType);
973+
assertThatFormula(fpmgr.assignment(fpFromBv, fp)).isTautological();
974+
}
975+
}
976+
977+
@Test
978+
public void fpFrom64BitPattern() throws SolverException, InterruptedException {
979+
for (double d : getListOfDoubles()) {
980+
long bits = Double.doubleToRawLongBits(d);
981+
long exponent = (bits >>> 52) & 0x7FF;
982+
long mantissa = bits & 0xFFFFFFFFFFFFFL;
983+
boolean sign = bits < 0; // equal to: (doubleBits >>> 63) & 1;
984+
final FloatingPointFormula fpFromBv =
985+
fpmgr.makeNumber(
986+
BigInteger.valueOf(exponent), BigInteger.valueOf(mantissa), sign, doublePrecType);
987+
final FloatingPointFormula fp = fpmgr.makeNumber(d, doublePrecType);
988+
assertThatFormula(fpmgr.assignment(fpFromBv, fp)).isTautological();
989+
}
961990
}
962991
}

0 commit comments

Comments
 (0)