Index: lib/Support/APFloat.cpp =================================================================== --- lib/Support/APFloat.cpp +++ lib/Support/APFloat.cpp @@ -3045,7 +3045,9 @@ assert(partCount()==2); sign = static_cast(i2>>15); - if (myexponent==0 && mysignificand==0) { + if (myexponent != 0x7fff && mysignificand == 0) { + // if myexponent==0 this is a true zero + // if myexponent!=0 this is an unnormal value that happens to be zero // exponent, significand meaningless category = fcZero; } else if (myexponent==0x7fff && mysignificand==0x8000000000000000ULL) { Index: unittests/ADT/APFloatTest.cpp =================================================================== --- unittests/ADT/APFloatTest.cpp +++ unittests/ADT/APFloatTest.cpp @@ -983,6 +983,13 @@ ASSERT_EQ("8.73183400000000010e+02", convertToString(873.1834, 0, 0, false)); ASSERT_EQ("1.79769313486231570e+308", convertToString(1.7976931348623157E+308, 0, 0, false)); + + { + SmallString<64> Str; + APFloat UnnormalZero(APFloat::x87DoubleExtended(), APInt(80, {0, 1})); + UnnormalZero.toString(Str); + ASSERT_EQ("0", Str); + } } TEST(APFloatTest, toInteger) {