@@ -777,12 +777,16 @@ private List<Float> getListOfFloats() {
777
777
Float .MAX_VALUE ,
778
778
Float .POSITIVE_INFINITY ,
779
779
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 );
782
785
783
786
for (int i = 1 ; i < 20 ; i ++) {
784
787
for (int j = 1 ; j < 20 ; j ++) {
785
788
flts .add ((float ) (i * Math .pow (10 , j )));
789
+ flts .add ((float ) (-i * Math .pow (10 , j )));
786
790
}
787
791
}
788
792
@@ -806,12 +810,16 @@ private List<Double> getListOfDoubles() {
806
810
Double .MAX_VALUE ,
807
811
Double .POSITIVE_INFINITY ,
808
812
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 );
811
818
812
819
for (int i = 1 ; i < 20 ; i ++) {
813
820
for (int j = 1 ; j < 20 ; j ++) {
814
821
dbls .add (i * Math .pow (10 , j ));
822
+ dbls .add (-i * Math .pow (10 , j ));
815
823
}
816
824
}
817
825
@@ -952,11 +960,32 @@ public void failOnInvalidString() {
952
960
}
953
961
954
962
@ 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
+ }
961
990
}
962
991
}
0 commit comments