llvm.org GIT mirror llvm / 3e7735f
APFloat::roundToIntegral: Special values don't keep the exponent value up to date, don't rely on it. Add a couple of unit tests for special floats. Fixes 13929, found by MemorySanitizer. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@164698 91177308-0d34-0410-b5e6-96231b3b80d8 Benjamin Kramer 6 years ago
2 changed file(s) with 18 addition(s) and 1 deletion(s). Raw diff Collapse all Expand all
17741774 // If the exponent is large enough, we know that this value is already
17751775 // integral, and the arithmetic below would potentially cause it to saturate
17761776 // to +/-Inf. Bail out early instead.
1777 if (exponent+1 >= (int)semanticsPrecision(*semantics))
1777 if (category == fcNormal && exponent+1 >= (int)semanticsPrecision(*semantics))
17781778 return opOK;
17791779
17801780 // The algorithm here is quite simple: we add 2^(p-1), where p is the
688688 P = R;
689689 P.roundToIntegral(APFloat::rmNearestTiesToEven);
690690 EXPECT_EQ(R.convertToDouble(), P.convertToDouble());
691
692 P = APFloat::getZero(APFloat::IEEEdouble);
693 P.roundToIntegral(APFloat::rmTowardZero);
694 EXPECT_EQ(0.0, P.convertToDouble());
695 P = APFloat::getZero(APFloat::IEEEdouble, true);
696 P.roundToIntegral(APFloat::rmTowardZero);
697 EXPECT_EQ(-0.0, P.convertToDouble());
698 P = APFloat::getNaN(APFloat::IEEEdouble);
699 P.roundToIntegral(APFloat::rmTowardZero);
700 EXPECT_TRUE(IsNAN(P.convertToDouble()));
701 P = APFloat::getInf(APFloat::IEEEdouble);
702 P.roundToIntegral(APFloat::rmTowardZero);
703 EXPECT_TRUE(IsInf(P.convertToDouble()) && P.convertToDouble() > 0.0);
704 P = APFloat::getInf(APFloat::IEEEdouble, true);
705 P.roundToIntegral(APFloat::rmTowardZero);
706 EXPECT_TRUE(IsInf(P.convertToDouble()) && P.convertToDouble() < 0.0);
707
691708 }
692709
693710 TEST(APFloatTest, getLargest) {