@@ -189,7 +189,6 @@ Double Double::operator/=(const Double &target) const {
189189}
190190
191191int 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
290289double 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
0 commit comments