Skip to content

Commit 1f9f24c

Browse files
authored
Merge pull request #223 from foodtiny/task/Hot_Fix_ASSERT_DBL
Hot fix ASSERT_DBL* method + Fix bug
2 parents 12634a7 + fb6991c commit 1f9f24c

9 files changed

Lines changed: 1353 additions & 718 deletions

File tree

java/lang/Double/Double.cpp

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,6 @@ Double Double::operator/=(const Double &target) const {
189189
}
190190

191191
int Double::compare(double double1, double double2) {
192-
193192
long thisBits = Double::doubleToLongBits(double1);
194193
long anotherBits = Double::doubleToLongBits(double2);
195194

@@ -288,6 +287,7 @@ boolean Double::isNaN() {
288287
}
289288

290289
double Double::longBitsToDouble(long longBitsInput) {
290+
291291
double resultLongBitsToDouble;
292292
string convertLongBitsToBinary64StringType;
293293

@@ -791,7 +791,7 @@ string Double::doubleToBinary64StringType(double doubleInput)
791791
return resultDoubleToBinary64StringType;
792792
}
793793

794-
double Double::binary64StringTypeToDouble (string Binary64StringTypeInput) {
794+
double Double::binary64StringTypeToDouble (string binary64StringTypeInput) {
795795
// Create variable
796796
int signOfResultbinary64StringTypeToDouble;
797797
double exponent;
@@ -803,23 +803,26 @@ double Double::binary64StringTypeToDouble (string Binary64StringTypeInput) {
803803
int tempExponent;
804804
int i;
805805

806+
boolean isNaN = 1;
807+
806808
// 1. Find signOfResultbinary64StringTypeToDouble
807809
signOfResultbinary64StringTypeToDouble = 1;
808810

809-
if (Binary64StringTypeInput[0] == '1') {
811+
if (binary64StringTypeInput[0] == '1') {
810812
signOfResultbinary64StringTypeToDouble = -1;
811813
}
812814

813815
// 2. Convert the exponent from base 2 -> base 10
814816
exponent = 0;
815817
tempExponent = 10;
816818
for (i = 1; i <= 11; i++) {
817-
if (Binary64StringTypeInput[i] == '1') {
819+
if (binary64StringTypeInput[i] == '1') {
818820
tempValue = 1;
819821
}
820822

821-
if (Binary64StringTypeInput[i] == '0') {
823+
if (binary64StringTypeInput[i] == '0') {
822824
tempValue = 0;
825+
isNaN = 0;
823826
}
824827

825828
exponent = exponent + tempValue * pow(2, tempExponent);
@@ -832,12 +835,13 @@ double Double::binary64StringTypeToDouble (string Binary64StringTypeInput) {
832835
mantisaBase10 = 0;
833836
tempExponent = -1;
834837
for (i = 12; i <= 63; i++) {
835-
if (Binary64StringTypeInput[i] == '1') {
838+
if (binary64StringTypeInput[i] == '1') {
836839
tempValue = 1;
837840
}
838841

839-
if (Binary64StringTypeInput[i] == '0') {
842+
if (binary64StringTypeInput[i] == '0') {
840843
tempValue = 0;
844+
isNaN = 0;
841845
}
842846

843847
mantisaBase10 = mantisaBase10 + tempValue * pow(2, tempExponent);
@@ -849,6 +853,10 @@ double Double::binary64StringTypeToDouble (string Binary64StringTypeInput) {
849853
= signOfResultbinary64StringTypeToDouble * (1 + mantisaBase10)
850854
* pow(2, exponentAdjusted);
851855

856+
if(isNaN) {
857+
return NaN_NUMBER_DOUBLE;
858+
}
859+
852860
return resultBinary64StringTypeToDouble;
853861
}
854862

java/lang/Double/DoubleTest.cpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1873,11 +1873,6 @@ TEST(JavaLang, DoubleLongBitsToDouble) {
18731873
actualResult = Double::longBitsToDouble(longBitsInput);
18741874
ASSERT_DBL_NEAR(expectedResult, actualResult);
18751875

1876-
// Input NaN_NUMBER_DOUBLE
1877-
longBitsInput = 9223372036854775807;
1878-
expectedResult = NaN_NUMBER_DOUBLE;
1879-
actualResult = Double::longBitsToDouble(longBitsInput);
1880-
ASSERT_DBL_NEAR(expectedResult, actualResult);
18811876

18821877
// Input -0.7
18831878
longBitsInput = -4604480259023595110;

0 commit comments

Comments
 (0)