llvm.org GIT mirror llvm / 7aa1c32
Implement APFloat::isDenormal() git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@171764 91177308-0d34-0410-b5e6-96231b3b80d8 Shuxin Yang 6 years ago
3 changed file(s) with 60 addition(s) and 0 deletion(s). Raw diff Collapse all Expand all
326326 bool isNegative() const { return sign; }
327327 bool isPosZero() const { return isZero() && !isNegative(); }
328328 bool isNegZero() const { return isZero() && isNegative(); }
329 bool isDenormal() const;
329330
330331 APFloat& operator=(const APFloat &);
331332
693693 }
694694
695695 return *this;
696 }
697
698 bool
699 APFloat::isDenormal() const {
700 return isNormal() && (exponent == semantics->minExponent) &&
701 (APInt::tcExtractBit(significandParts(),
702 semantics->precision - 1) == 0);
696703 }
697704
698705 bool
3131 }
3232
3333 namespace {
34
35 TEST(APFloatTest, Denormal) {
36 APFloat::roundingMode rdmd = APFloat::rmNearestTiesToEven;
37
38 // Test single precision
39 {
40 const char *MinNormalStr = "1.17549435082228750797e-38";
41 EXPECT_FALSE(APFloat(APFloat::IEEEsingle, MinNormalStr).isDenormal());
42 EXPECT_FALSE(APFloat(APFloat::IEEEsingle, 0.0).isDenormal());
43
44 APFloat Val2(APFloat::IEEEsingle, 2.0e0);
45 APFloat T(APFloat::IEEEsingle, MinNormalStr);
46 T.divide(Val2, rdmd);
47 EXPECT_TRUE(T.isDenormal());
48 }
49
50 // Test double precision
51 {
52 const char *MinNormalStr = "2.22507385850720138309e-308";
53 EXPECT_FALSE(APFloat(APFloat::IEEEdouble, MinNormalStr).isDenormal());
54 EXPECT_FALSE(APFloat(APFloat::IEEEdouble, 0.0).isDenormal());
55
56 APFloat Val2(APFloat::IEEEdouble, 2.0e0);
57 APFloat T(APFloat::IEEEdouble, MinNormalStr);
58 T.divide(Val2, rdmd);
59 EXPECT_TRUE(T.isDenormal());
60 }
61
62 // Test Intel double-ext
63 {
64 const char *MinNormalStr = "3.36210314311209350626e-4932";
65 EXPECT_FALSE(APFloat(APFloat::x87DoubleExtended, MinNormalStr).isDenormal());
66 EXPECT_FALSE(APFloat(APFloat::x87DoubleExtended, 0.0).isDenormal());
67
68 APFloat Val2(APFloat::x87DoubleExtended, 2.0e0);
69 APFloat T(APFloat::x87DoubleExtended, MinNormalStr);
70 T.divide(Val2, rdmd);
71 EXPECT_TRUE(T.isDenormal());
72 }
73
74 // Test quadruple precision
75 {
76 const char *MinNormalStr = "3.36210314311209350626267781732175260e-4932";
77 EXPECT_FALSE(APFloat(APFloat::IEEEquad, MinNormalStr).isDenormal());
78 EXPECT_FALSE(APFloat(APFloat::IEEEquad, 0.0).isDenormal());
79
80 APFloat Val2(APFloat::IEEEquad, 2.0e0);
81 APFloat T(APFloat::IEEEquad, MinNormalStr);
82 T.divide(Val2, rdmd);
83 EXPECT_TRUE(T.isDenormal());
84 }
85 }
3486
3587 TEST(APFloatTest, Zero) {
3688 EXPECT_EQ(0.0f, APFloat(0.0f).convertToFloat());