diff options
author | Shuxin Yang <shuxin.llvm@gmail.com> | 2013-05-13 18:03:12 +0000 |
---|---|---|
committer | Shuxin Yang <shuxin.llvm@gmail.com> | 2013-05-13 18:03:12 +0000 |
commit | 4b6b53b0cec4fcf4d570daed3be41d6147d05224 (patch) | |
tree | 5b3049b8c58e4fb7b2aa4cf7ad83f89e689ba769 /unittests | |
parent | 151687cb8c4fc65fefcd8964a0c3d77680e90a5c (diff) | |
download | external_llvm-4b6b53b0cec4fcf4d570daed3be41d6147d05224.zip external_llvm-4b6b53b0cec4fcf4d570daed3be41d6147d05224.tar.gz external_llvm-4b6b53b0cec4fcf4d570daed3be41d6147d05224.tar.bz2 |
Fix a bug that APFloat::fusedMultiplyAdd() mistakenly evaluate "14.5f * -14.5f + 225.0f" to 225.0f.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@181715 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'unittests')
-rw-r--r-- | unittests/ADT/APFloatTest.cpp | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/unittests/ADT/APFloatTest.cpp b/unittests/ADT/APFloatTest.cpp index 2789835..099f6db 100644 --- a/unittests/ADT/APFloatTest.cpp +++ b/unittests/ADT/APFloatTest.cpp @@ -33,6 +33,29 @@ static std::string convertToString(double d, unsigned Prec, unsigned Pad) { namespace { +TEST(APFloatTest, FMA) { + APFloat::roundingMode rdmd = APFloat::rmNearestTiesToEven; + + { + APFloat f1(14.5f); + APFloat f2(-14.5f); + APFloat f3(225.0f); + f1.fusedMultiplyAdd(f2, f3, APFloat::rmNearestTiesToEven); + EXPECT_EQ(14.75f, f1.convertToFloat()); + } + + { + APFloat Val2(2.0f); + APFloat f1((float)1.17549435e-38F); + APFloat f2((float)1.17549435e-38F); + f1.divide(Val2, rdmd); + f2.divide(Val2, rdmd); + APFloat f3(12.0f); + f1.fusedMultiplyAdd(f2, f3, APFloat::rmNearestTiesToEven); + EXPECT_EQ(12.0f, f1.convertToFloat()); + } +} + TEST(APFloatTest, Denormal) { APFloat::roundingMode rdmd = APFloat::rmNearestTiesToEven; |