llvm.org GIT mirror llvm / 20a600c
Replace APFloatBase static fltSemantics data members with getter functions At least the plugin used by the LibreOffice build (<https://wiki.documentfoundation.org/Development/Clang_plugins>) indirectly uses those members (through inline functions in LLVM/Clang include files in turn using them), but they are not exported by utils/extract_symbols.py on Windows, and accessing data across DLL/EXE boundaries on Windows is generally problematic. Differential Revision: https://reviews.llvm.org/D26671 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@289647 91177308-0d34-0410-b5e6-96231b3b80d8 Stephan Bergmann 3 years ago
36 changed file(s) with 1222 addition(s) and 1200 deletion(s). Raw diff Collapse all Expand all
135135 /// \name Floating Point Semantics.
136136 /// @{
137137
138 static const fltSemantics IEEEhalf;
139 static const fltSemantics IEEEsingle;
140 static const fltSemantics IEEEdouble;
141 static const fltSemantics IEEEquad;
142 static const fltSemantics PPCDoubleDouble;
143 static const fltSemantics x87DoubleExtended;
138 static const fltSemantics &IEEEhalf();
139 static const fltSemantics &IEEEsingle();
140 static const fltSemantics &IEEEdouble();
141 static const fltSemantics &IEEEquad();
142 static const fltSemantics &PPCDoubleDouble();
143 static const fltSemantics &x87DoubleExtended();
144144
145145 /// A Pseudo fltsemantic used to construct APFloats that cannot conflict with
146146 /// anything real.
147 static const fltSemantics Bogus;
147 static const fltSemantics &Bogus();
148148
149149 /// @}
150150
663663 explicit Storage(IEEEFloat F, const fltSemantics &S);
664664 explicit Storage(DoubleAPFloat F, const fltSemantics &S)
665665 : Double(std::move(F)) {
666 assert(&S == &PPCDoubleDouble);
666 assert(&S == &PPCDoubleDouble());
667667 }
668668
669669 template
740740 static_assert(std::is_same::value ||
741741 std::is_same::value, "");
742742 if (std::is_same::value) {
743 return &Semantics == &PPCDoubleDouble;
744 }
745 return &Semantics != &PPCDoubleDouble;
743 return &Semantics == &PPCDoubleDouble();
744 }
745 return &Semantics != &PPCDoubleDouble();
746746 }
747747
748748 IEEEFloat &getIEEE() {
792792 // FIXME: This is due to clang 3.3 (or older version) always checks for the
793793 // default constructor in an array aggregate initialization, even if no
794794 // elements in the array is default initialized.
795 APFloat() : U(IEEEdouble) {
795 APFloat() : U(IEEEdouble()) {
796796 llvm_unreachable("This is a workaround for old clang.");
797797 }
798798
819819 APFloat(const fltSemantics &Semantics, uninitializedTag)
820820 : U(Semantics, uninitialized) {}
821821 APFloat(const fltSemantics &Semantics, const APInt &I) : U(Semantics, I) {}
822 explicit APFloat(double d) : U(IEEEFloat(d), IEEEdouble) {}
823 explicit APFloat(float f) : U(IEEEFloat(f), IEEEsingle) {}
822 explicit APFloat(double d) : U(IEEEFloat(d), IEEEdouble()) {}
823 explicit APFloat(float f) : U(IEEEFloat(f), IEEEsingle()) {}
824824 APFloat(const APFloat &RHS) = default;
825825 APFloat(APFloat &&RHS) = default;
826826
10721072 // This is for internal test only.
10731073 // TODO: Remove it after the PPCDoubleDouble transition.
10741074 const APFloat &getSecondFloat() const {
1075 assert(&getSemantics() == &PPCDoubleDouble);
1075 assert(&getSemantics() == &PPCDoubleDouble());
10761076 return U.Double.getSecond();
10771077 }
10781078
11791179 static const fltSemantics &EVTToAPFloatSemantics(EVT VT) {
11801180 switch (VT.getScalarType().getSimpleVT().SimpleTy) {
11811181 default: llvm_unreachable("Unknown FP format");
1182 case MVT::f16: return APFloat::IEEEhalf;
1183 case MVT::f32: return APFloat::IEEEsingle;
1184 case MVT::f64: return APFloat::IEEEdouble;
1185 case MVT::f80: return APFloat::x87DoubleExtended;
1186 case MVT::f128: return APFloat::IEEEquad;
1187 case MVT::ppcf128: return APFloat::PPCDoubleDouble;
1182 case MVT::f16: return APFloat::IEEEhalf();
1183 case MVT::f32: return APFloat::IEEEsingle();
1184 case MVT::f64: return APFloat::IEEEdouble();
1185 case MVT::f80: return APFloat::x87DoubleExtended();
1186 case MVT::f128: return APFloat::IEEEquad();
1187 case MVT::ppcf128: return APFloat::PPCDoubleDouble();
11881188 }
11891189 }
11901190
165165
166166 const fltSemantics &getFltSemantics() const {
167167 switch (getTypeID()) {
168 case HalfTyID: return APFloat::IEEEhalf;
169 case FloatTyID: return APFloat::IEEEsingle;
170 case DoubleTyID: return APFloat::IEEEdouble;
171 case X86_FP80TyID: return APFloat::x87DoubleExtended;
172 case FP128TyID: return APFloat::IEEEquad;
173 case PPC_FP128TyID: return APFloat::PPCDoubleDouble;
168 case HalfTyID: return APFloat::IEEEhalf();
169 case FloatTyID: return APFloat::IEEEsingle();
170 case DoubleTyID: return APFloat::IEEEdouble();
171 case X86_FP80TyID: return APFloat::x87DoubleExtended();
172 case FP128TyID: return APFloat::IEEEquad();
173 case PPC_FP128TyID: return APFloat::PPCDoubleDouble();
174174 default: llvm_unreachable("Invalid floating type");
175175 }
176176 }
14411441 if (Ty->isHalfTy()) {
14421442 APFloat APF(V);
14431443 bool unused;
1444 APF.convert(APFloat::IEEEhalf, APFloat::rmNearestTiesToEven, &unused);
1444 APF.convert(APFloat::IEEEhalf(), APFloat::rmNearestTiesToEven, &unused);
14451445 return ConstantFP::get(Ty->getContext(), APF);
14461446 }
14471447 if (Ty->isFloatTy())
15321532
15331533 bool unused;
15341534 APFloat APF = Op->getValueAPF();
1535 APF.convert(APFloat::IEEEdouble, APFloat::rmNearestTiesToEven, &unused);
1535 APF.convert(APFloat::IEEEdouble(), APFloat::rmNearestTiesToEven, &unused);
15361536 return APF.convertToDouble();
15371537 }
15381538
15501550 APFloat Val(Op->getValueAPF());
15511551
15521552 bool lost = false;
1553 Val.convert(APFloat::IEEEhalf, APFloat::rmNearestTiesToEven, &lost);
1553 Val.convert(APFloat::IEEEhalf(), APFloat::rmNearestTiesToEven, &lost);
15541554
15551555 return ConstantInt::get(Ty->getContext(), Val.bitcastToAPInt());
15561556 }
17251725 case Intrinsic::bitreverse:
17261726 return ConstantInt::get(Ty->getContext(), Op->getValue().reverseBits());
17271727 case Intrinsic::convert_from_fp16: {
1728 APFloat Val(APFloat::IEEEhalf, Op->getValue());
1728 APFloat Val(APFloat::IEEEhalf(), Op->getValue());
17291729
17301730 bool lost = false;
17311731 APFloat::opStatus status = Val.convert(
875875 // HexFPConstant - Floating point constant represented in IEEE format as a
876876 // hexadecimal number for when exponential notation is not precise enough.
877877 // Half, Float, and double only.
878 APFloatVal = APFloat(APFloat::IEEEdouble,
878 APFloatVal = APFloat(APFloat::IEEEdouble(),
879879 APInt(64, HexIntToVal(TokStart + 2, CurPtr)));
880880 return lltok::APFloat;
881881 }
886886 case 'K':
887887 // F80HexFPConstant - x87 long double in hexadecimal format (10 bytes)
888888 FP80HexToIntPair(TokStart+3, CurPtr, Pair);
889 APFloatVal = APFloat(APFloat::x87DoubleExtended, APInt(80, Pair));
889 APFloatVal = APFloat(APFloat::x87DoubleExtended(), APInt(80, Pair));
890890 return lltok::APFloat;
891891 case 'L':
892892 // F128HexFPConstant - IEEE 128-bit in hexadecimal format (16 bytes)
893893 HexToIntPair(TokStart+3, CurPtr, Pair);
894 APFloatVal = APFloat(APFloat::IEEEquad, APInt(128, Pair));
894 APFloatVal = APFloat(APFloat::IEEEquad(), APInt(128, Pair));
895895 return lltok::APFloat;
896896 case 'M':
897897 // PPC128HexFPConstant - PowerPC 128-bit in hexadecimal format (16 bytes)
898898 HexToIntPair(TokStart+3, CurPtr, Pair);
899 APFloatVal = APFloat(APFloat::PPCDoubleDouble, APInt(128, Pair));
899 APFloatVal = APFloat(APFloat::PPCDoubleDouble(), APInt(128, Pair));
900900 return lltok::APFloat;
901901 case 'H':
902 APFloatVal = APFloat(APFloat::IEEEhalf,
902 APFloatVal = APFloat(APFloat::IEEEhalf(),
903903 APInt(16,HexIntToVal(TokStart+3, CurPtr)));
904904 return lltok::APFloat;
905905 }
966966 }
967967 }
968968
969 APFloatVal = APFloat(APFloat::IEEEdouble,
969 APFloatVal = APFloat(APFloat::IEEEdouble(),
970970 StringRef(TokStart, CurPtr - TokStart));
971971 return lltok::APFloat;
972972 }
10031003 }
10041004 }
10051005
1006 APFloatVal = APFloat(APFloat::IEEEdouble,
1006 APFloatVal = APFloat(APFloat::IEEEdouble(),
10071007 StringRef(TokStart, CurPtr - TokStart));
10081008 return lltok::APFloat;
10091009 }
44594459
44604460 // The lexer has no type info, so builds all half, float, and double FP
44614461 // constants as double. Fix this here. Long double does not need this.
4462 if (&ID.APFloatVal.getSemantics() == &APFloat::IEEEdouble) {
4462 if (&ID.APFloatVal.getSemantics() == &APFloat::IEEEdouble()) {
44634463 bool Ignored;
44644464 if (Ty->isHalfTy())
4465 ID.APFloatVal.convert(APFloat::IEEEhalf, APFloat::rmNearestTiesToEven,
4465 ID.APFloatVal.convert(APFloat::IEEEhalf(), APFloat::rmNearestTiesToEven,
44664466 &Ignored);
44674467 else if (Ty->isFloatTy())
4468 ID.APFloatVal.convert(APFloat::IEEEsingle, APFloat::rmNearestTiesToEven,
4468 ID.APFloatVal.convert(APFloat::IEEEsingle(), APFloat::rmNearestTiesToEven,
44694469 &Ignored);
44704470 }
44714471 V = ConstantFP::get(Context, ID.APFloatVal);
19951995 if (Record.empty())
19961996 return error("Invalid record");
19971997 if (CurTy->isHalfTy())
1998 V = ConstantFP::get(Context, APFloat(APFloat::IEEEhalf,
1998 V = ConstantFP::get(Context, APFloat(APFloat::IEEEhalf(),
19991999 APInt(16, (uint16_t)Record[0])));
20002000 else if (CurTy->isFloatTy())
2001 V = ConstantFP::get(Context, APFloat(APFloat::IEEEsingle,
2001 V = ConstantFP::get(Context, APFloat(APFloat::IEEEsingle(),
20022002 APInt(32, (uint32_t)Record[0])));
20032003 else if (CurTy->isDoubleTy())
2004 V = ConstantFP::get(Context, APFloat(APFloat::IEEEdouble,
2004 V = ConstantFP::get(Context, APFloat(APFloat::IEEEdouble(),
20052005 APInt(64, Record[0])));
20062006 else if (CurTy->isX86_FP80Ty()) {
20072007 // Bits are not stored the same way as a normal i80 APInt, compensate.
20082008 uint64_t Rearrange[2];
20092009 Rearrange[0] = (Record[1] & 0xffffLL) | (Record[0] << 16);
20102010 Rearrange[1] = Record[0] >> 48;
2011 V = ConstantFP::get(Context, APFloat(APFloat::x87DoubleExtended,
2011 V = ConstantFP::get(Context, APFloat(APFloat::x87DoubleExtended(),
20122012 APInt(80, Rearrange)));
20132013 } else if (CurTy->isFP128Ty())
2014 V = ConstantFP::get(Context, APFloat(APFloat::IEEEquad,
2014 V = ConstantFP::get(Context, APFloat(APFloat::IEEEquad(),
20152015 APInt(128, Record)));
20162016 else if (CurTy->isPPC_FP128Ty())
2017 V = ConstantFP::get(Context, APFloat(APFloat::PPCDoubleDouble,
2017 V = ConstantFP::get(Context, APFloat(APFloat::PPCDoubleDouble(),
20182018 APInt(128, Record)));
20192019 else
20202020 V = UndefValue::get(CurTy);
757757 // There is no good way to print long double. Convert a copy to
758758 // double. Ah well, it's only a comment.
759759 bool ignored;
760 APF.convert(APFloat::IEEEdouble, APFloat::rmNearestTiesToEven,
760 APF.convert(APFloat::IEEEdouble(), APFloat::rmNearestTiesToEven,
761761 &ignored);
762762 OS << "(long double) " << APF.convertToDouble();
763763 }
400400 } else if (getFPImm()->getType()->isHalfTy()) {
401401 APFloat APF = getFPImm()->getValueAPF();
402402 bool Unused;
403 APF.convert(APFloat::IEEEsingle, APFloat::rmNearestTiesToEven, &Unused);
403 APF.convert(APFloat::IEEEsingle(), APFloat::rmNearestTiesToEven, &Unused);
404404 OS << "half " << APF.convertToFloat();
405405 } else {
406406 OS << getFPImm()->getValueAPF().convertToDouble();
14651465
14661466 // TODO: Are there fast-math-flags to propagate to this FADD?
14671467 Lo = DAG.getNode(ISD::FADD, dl, VT, Hi,
1468 DAG.getConstantFP(APFloat(APFloat::PPCDoubleDouble,
1468 DAG.getConstantFP(APFloat(APFloat::PPCDoubleDouble(),
14691469 APInt(128, Parts)),
14701470 dl, MVT::ppcf128));
14711471 Lo = DAG.getSelectCC(dl, Src, DAG.getConstant(0, dl, SrcVT),
16301630 assert(N->getOperand(0).getValueType() == MVT::ppcf128 &&
16311631 "Logic only correct for ppcf128!");
16321632 const uint64_t TwoE31[] = {0x41e0000000000000LL, 0};
1633 APFloat APF = APFloat(APFloat::PPCDoubleDouble, APInt(128, TwoE31));
1633 APFloat APF = APFloat(APFloat::PPCDoubleDouble(), APInt(128, TwoE31));
16341634 SDValue Tmp = DAG.getConstantFP(APF, dl, MVT::ppcf128);
16351635 // X>=2^31 ? (int)(X-2^31)+0x80000000 : (int)X
16361636 // FIXME: generated code sucks.
31903190 }
31913191 case ISD::BITCAST:
31923192 if (VT == MVT::f16 && C->getValueType(0) == MVT::i16)
3193 return getConstantFP(APFloat(APFloat::IEEEhalf, Val), DL, VT);
3193 return getConstantFP(APFloat(APFloat::IEEEhalf(), Val), DL, VT);
31943194 if (VT == MVT::f32 && C->getValueType(0) == MVT::i32)
3195 return getConstantFP(APFloat(APFloat::IEEEsingle, Val), DL, VT);
3195 return getConstantFP(APFloat(APFloat::IEEEsingle(), Val), DL, VT);
31963196 if (VT == MVT::f64 && C->getValueType(0) == MVT::i64)
3197 return getConstantFP(APFloat(APFloat::IEEEdouble, Val), DL, VT);
3197 return getConstantFP(APFloat(APFloat::IEEEdouble(), Val), DL, VT);
31983198 if (VT == MVT::f128 && C->getValueType(0) == MVT::i128)
3199 return getConstantFP(APFloat(APFloat::IEEEquad, Val), DL, VT);
3199 return getConstantFP(APFloat(APFloat::IEEEquad(), Val), DL, VT);
32003200 break;
32013201 case ISD::BSWAP:
32023202 return getConstant(Val.byteSwap(), DL, VT, C->isTargetOpcode(),
41714171 /// getF32Constant - Get 32-bit floating point constant.
41724172 static SDValue getF32Constant(SelectionDAG &DAG, unsigned Flt,
41734173 const SDLoc &dl) {
4174 return DAG.getConstantFP(APFloat(APFloat::IEEEsingle, APInt(32, Flt)), dl,
4174 return DAG.getConstantFP(APFloat(APFloat::IEEEsingle(), APInt(32, Flt)), dl,
41754175 MVT::f32);
41764176 }
41774177
424424 } else if (const ConstantSDNode *CSDN = dyn_cast(this)) {
425425 OS << '<' << CSDN->getAPIntValue() << '>';
426426 } else if (const ConstantFPSDNode *CSDN = dyn_cast(this)) {
427 if (&CSDN->getValueAPF().getSemantics()==&APFloat::IEEEsingle)
427 if (&CSDN->getValueAPF().getSemantics()==&APFloat::IEEEsingle())
428428 OS << '<' << CSDN->getValueAPF().convertToFloat() << '>';
429 else if (&CSDN->getValueAPF().getSemantics()==&APFloat::IEEEdouble)
429 else if (&CSDN->getValueAPF().getSemantics()==&APFloat::IEEEdouble())
430430 OS << '<' << CSDN->getValueAPF().convertToDouble() << '>';
431431 else {
432432 OS << "
691691 else if (CE->getType()->isDoubleTy())
692692 GV.DoubleVal = GV.IntVal.roundToDouble();
693693 else if (CE->getType()->isX86_FP80Ty()) {
694 APFloat apf = APFloat::getZero(APFloat::x87DoubleExtended);
694 APFloat apf = APFloat::getZero(APFloat::x87DoubleExtended());
695695 (void)apf.convertFromAPInt(GV.IntVal,
696696 false,
697697 APFloat::rmNearestTiesToEven);
706706 else if (CE->getType()->isDoubleTy())
707707 GV.DoubleVal = GV.IntVal.signedRoundToDouble();
708708 else if (CE->getType()->isX86_FP80Ty()) {
709 APFloat apf = APFloat::getZero(APFloat::x87DoubleExtended);
709 APFloat apf = APFloat::getZero(APFloat::x87DoubleExtended());
710710 (void)apf.convertFromAPInt(GV.IntVal,
711711 true,
712712 APFloat::rmNearestTiesToEven);
723723 else if (Op0->getType()->isDoubleTy())
724724 GV.IntVal = APIntOps::RoundDoubleToAPInt(GV.DoubleVal, BitWidth);
725725 else if (Op0->getType()->isX86_FP80Ty()) {
726 APFloat apf = APFloat(APFloat::x87DoubleExtended, GV.IntVal);
726 APFloat apf = APFloat(APFloat::x87DoubleExtended(), GV.IntVal);
727727 uint64_t v;
728728 bool ignored;
729729 (void)apf.convertToInteger(&v, BitWidth,
11051105 }
11061106
11071107 if (const ConstantFP *CFP = dyn_cast(CV)) {
1108 if (&CFP->getValueAPF().getSemantics() == &APFloat::IEEEsingle ||
1109 &CFP->getValueAPF().getSemantics() == &APFloat::IEEEdouble) {
1108 if (&CFP->getValueAPF().getSemantics() == &APFloat::IEEEsingle() ||
1109 &CFP->getValueAPF().getSemantics() == &APFloat::IEEEdouble()) {
11101110 // We would like to output the FP constant value in exponential notation,
11111111 // but we cannot do this if doing so will lose precision. Check here to
11121112 // make sure that we only output it in exponential format if we can parse
11131113 // the value back and get the same value.
11141114 //
11151115 bool ignored;
1116 bool isDouble = &CFP->getValueAPF().getSemantics()==&APFloat::IEEEdouble;
1116 bool isDouble = &CFP->getValueAPF().getSemantics()==&APFloat::IEEEdouble();
11171117 bool isInf = CFP->getValueAPF().isInfinity();
11181118 bool isNaN = CFP->getValueAPF().isNaN();
11191119 if (!isInf && !isNaN) {
11301130 ((StrVal[0] == '-' || StrVal[0] == '+') &&
11311131 (StrVal[1] >= '0' && StrVal[1] <= '9'))) {
11321132 // Reparse stringized version!
1133 if (APFloat(APFloat::IEEEdouble, StrVal).convertToDouble() == Val) {
1133 if (APFloat(APFloat::IEEEdouble(), StrVal).convertToDouble() == Val) {
11341134 Out << StrVal;
11351135 return;
11361136 }
11451145 APFloat apf = CFP->getValueAPF();
11461146 // Floats are represented in ASCII IR as double, convert.
11471147 if (!isDouble)
1148 apf.convert(APFloat::IEEEdouble, APFloat::rmNearestTiesToEven,
1148 apf.convert(APFloat::IEEEdouble(), APFloat::rmNearestTiesToEven,
11491149 &ignored);
11501150 Out << format_hex(apf.bitcastToAPInt().getZExtValue(), 0, /*Upper=*/true);
11511151 return;
11561156 // fixed number of hex digits.
11571157 Out << "0x";
11581158 APInt API = CFP->getValueAPF().bitcastToAPInt();
1159 if (&CFP->getValueAPF().getSemantics() == &APFloat::x87DoubleExtended) {
1159 if (&CFP->getValueAPF().getSemantics() == &APFloat::x87DoubleExtended()) {
11601160 Out << 'K';
11611161 Out << format_hex_no_prefix(API.getHiBits(16).getZExtValue(), 4,
11621162 /*Upper=*/true);
11631163 Out << format_hex_no_prefix(API.getLoBits(64).getZExtValue(), 16,
11641164 /*Upper=*/true);
11651165 return;
1166 } else if (&CFP->getValueAPF().getSemantics() == &APFloat::IEEEquad) {
1166 } else if (&CFP->getValueAPF().getSemantics() == &APFloat::IEEEquad()) {
11671167 Out << 'L';
11681168 Out << format_hex_no_prefix(API.getLoBits(64).getZExtValue(), 16,
11691169 /*Upper=*/true);
11701170 Out << format_hex_no_prefix(API.getHiBits(64).getZExtValue(), 16,
11711171 /*Upper=*/true);
1172 } else if (&CFP->getValueAPF().getSemantics() == &APFloat::PPCDoubleDouble) {
1172 } else if (&CFP->getValueAPF().getSemantics() == &APFloat::PPCDoubleDouble()) {
11731173 Out << 'M';
11741174 Out << format_hex_no_prefix(API.getLoBits(64).getZExtValue(), 16,
11751175 /*Upper=*/true);
11761176 Out << format_hex_no_prefix(API.getHiBits(64).getZExtValue(), 16,
11771177 /*Upper=*/true);
1178 } else if (&CFP->getValueAPF().getSemantics() == &APFloat::IEEEhalf) {
1178 } else if (&CFP->getValueAPF().getSemantics() == &APFloat::IEEEhalf()) {
11791179 Out << 'H';
11801180 Out << format_hex_no_prefix(API.getZExtValue(), 4,
11811181 /*Upper=*/true);
589589 if (ConstantFP *FPC = dyn_cast(V)) {
590590 bool ignored;
591591 APFloat Val = FPC->getValueAPF();
592 Val.convert(DestTy->isHalfTy() ? APFloat::IEEEhalf :
593 DestTy->isFloatTy() ? APFloat::IEEEsingle :
594 DestTy->isDoubleTy() ? APFloat::IEEEdouble :
595 DestTy->isX86_FP80Ty() ? APFloat::x87DoubleExtended :
596 DestTy->isFP128Ty() ? APFloat::IEEEquad :
597 DestTy->isPPC_FP128Ty() ? APFloat::PPCDoubleDouble :
598 APFloat::Bogus,
592 Val.convert(DestTy->isHalfTy() ? APFloat::IEEEhalf() :
593 DestTy->isFloatTy() ? APFloat::IEEEsingle() :
594 DestTy->isDoubleTy() ? APFloat::IEEEdouble() :
595 DestTy->isX86_FP80Ty() ? APFloat::x87DoubleExtended() :
596 DestTy->isFP128Ty() ? APFloat::IEEEquad() :
597 DestTy->isPPC_FP128Ty() ? APFloat::PPCDoubleDouble() :
598 APFloat::Bogus(),
599599 APFloat::rmNearestTiesToEven, &ignored);
600600 return ConstantFP::get(V->getContext(), Val);
601601 }
197197 return ConstantInt::get(Ty, 0);
198198 case Type::HalfTyID:
199199 return ConstantFP::get(Ty->getContext(),
200 APFloat::getZero(APFloat::IEEEhalf));
200 APFloat::getZero(APFloat::IEEEhalf()));
201201 case Type::FloatTyID:
202202 return ConstantFP::get(Ty->getContext(),
203 APFloat::getZero(APFloat::IEEEsingle));
203 APFloat::getZero(APFloat::IEEEsingle()));
204204 case Type::DoubleTyID:
205205 return ConstantFP::get(Ty->getContext(),
206 APFloat::getZero(APFloat::IEEEdouble));
206 APFloat::getZero(APFloat::IEEEdouble()));
207207 case Type::X86_FP80TyID:
208208 return ConstantFP::get(Ty->getContext(),
209 APFloat::getZero(APFloat::x87DoubleExtended));
209 APFloat::getZero(APFloat::x87DoubleExtended()));
210210 case Type::FP128TyID:
211211 return ConstantFP::get(Ty->getContext(),
212 APFloat::getZero(APFloat::IEEEquad));
212 APFloat::getZero(APFloat::IEEEquad()));
213213 case Type::PPC_FP128TyID:
214214 return ConstantFP::get(Ty->getContext(),
215 APFloat(APFloat::PPCDoubleDouble,
215 APFloat(APFloat::PPCDoubleDouble(),
216216 APInt::getNullValue(128)));
217217 case Type::PointerTyID:
218218 return ConstantPointerNull::get(cast(Ty));
603603
604604 static const fltSemantics *TypeToFloatSemantics(Type *Ty) {
605605 if (Ty->isHalfTy())
606 return &APFloat::IEEEhalf;
606 return &APFloat::IEEEhalf();
607607 if (Ty->isFloatTy())
608 return &APFloat::IEEEsingle;
608 return &APFloat::IEEEsingle();
609609 if (Ty->isDoubleTy())
610 return &APFloat::IEEEdouble;
610 return &APFloat::IEEEdouble();
611611 if (Ty->isX86_FP80Ty())
612 return &APFloat::x87DoubleExtended;
612 return &APFloat::x87DoubleExtended();
613613 else if (Ty->isFP128Ty())
614 return &APFloat::IEEEquad;
614 return &APFloat::IEEEquad();
615615
616616 assert(Ty->isPPC_FP128Ty() && "Unknown FP format");
617 return &APFloat::PPCDoubleDouble;
617 return &APFloat::PPCDoubleDouble();
618618 }
619619
620620 void ConstantFP::anchor() { }
688688
689689 if (!Slot) {
690690 Type *Ty;
691 if (&V.getSemantics() == &APFloat::IEEEhalf)
691 if (&V.getSemantics() == &APFloat::IEEEhalf())
692692 Ty = Type::getHalfTy(Context);
693 else if (&V.getSemantics() == &APFloat::IEEEsingle)
693 else if (&V.getSemantics() == &APFloat::IEEEsingle())
694694 Ty = Type::getFloatTy(Context);
695 else if (&V.getSemantics() == &APFloat::IEEEdouble)
695 else if (&V.getSemantics() == &APFloat::IEEEdouble())
696696 Ty = Type::getDoubleTy(Context);
697 else if (&V.getSemantics() == &APFloat::x87DoubleExtended)
697 else if (&V.getSemantics() == &APFloat::x87DoubleExtended())
698698 Ty = Type::getX86_FP80Ty(Context);
699 else if (&V.getSemantics() == &APFloat::IEEEquad)
699 else if (&V.getSemantics() == &APFloat::IEEEquad())
700700 Ty = Type::getFP128Ty(Context);
701701 else {
702 assert(&V.getSemantics() == &APFloat::PPCDoubleDouble &&
702 assert(&V.getSemantics() == &APFloat::PPCDoubleDouble() &&
703703 "Unknown FP format");
704704 Ty = Type::getPPC_FP128Ty(Context);
705705 }
12091209
12101210 // FIXME rounding mode needs to be more flexible
12111211 case Type::HalfTyID: {
1212 if (&Val2.getSemantics() == &APFloat::IEEEhalf)
1212 if (&Val2.getSemantics() == &APFloat::IEEEhalf())
12131213 return true;
1214 Val2.convert(APFloat::IEEEhalf, APFloat::rmNearestTiesToEven, &losesInfo);
1214 Val2.convert(APFloat::IEEEhalf(), APFloat::rmNearestTiesToEven, &losesInfo);
12151215 return !losesInfo;
12161216 }
12171217 case Type::FloatTyID: {
1218 if (&Val2.getSemantics() == &APFloat::IEEEsingle)
1218 if (&Val2.getSemantics() == &APFloat::IEEEsingle())
12191219 return true;
1220 Val2.convert(APFloat::IEEEsingle, APFloat::rmNearestTiesToEven, &losesInfo);
1220 Val2.convert(APFloat::IEEEsingle(), APFloat::rmNearestTiesToEven, &losesInfo);
12211221 return !losesInfo;
12221222 }
12231223 case Type::DoubleTyID: {
1224 if (&Val2.getSemantics() == &APFloat::IEEEhalf ||
1225 &Val2.getSemantics() == &APFloat::IEEEsingle ||
1226 &Val2.getSemantics() == &APFloat::IEEEdouble)
1224 if (&Val2.getSemantics() == &APFloat::IEEEhalf() ||
1225 &Val2.getSemantics() == &APFloat::IEEEsingle() ||
1226 &Val2.getSemantics() == &APFloat::IEEEdouble())
12271227 return true;
1228 Val2.convert(APFloat::IEEEdouble, APFloat::rmNearestTiesToEven, &losesInfo);
1228 Val2.convert(APFloat::IEEEdouble(), APFloat::rmNearestTiesToEven, &losesInfo);
12291229 return !losesInfo;
12301230 }
12311231 case Type::X86_FP80TyID:
1232 return &Val2.getSemantics() == &APFloat::IEEEhalf ||
1233 &Val2.getSemantics() == &APFloat::IEEEsingle ||
1234 &Val2.getSemantics() == &APFloat::IEEEdouble ||
1235 &Val2.getSemantics() == &APFloat::x87DoubleExtended;
1232 return &Val2.getSemantics() == &APFloat::IEEEhalf() ||
1233 &Val2.getSemantics() == &APFloat::IEEEsingle() ||
1234 &Val2.getSemantics() == &APFloat::IEEEdouble() ||
1235 &Val2.getSemantics() == &APFloat::x87DoubleExtended();
12361236 case Type::FP128TyID:
1237 return &Val2.getSemantics() == &APFloat::IEEEhalf ||
1238 &Val2.getSemantics() == &APFloat::IEEEsingle ||
1239 &Val2.getSemantics() == &APFloat::IEEEdouble ||
1240 &Val2.getSemantics() == &APFloat::IEEEquad;
1237 return &Val2.getSemantics() == &APFloat::IEEEhalf() ||
1238 &Val2.getSemantics() == &APFloat::IEEEsingle() ||
1239 &Val2.getSemantics() == &APFloat::IEEEdouble() ||
1240 &Val2.getSemantics() == &APFloat::IEEEquad();
12411241 case Type::PPC_FP128TyID:
1242 return &Val2.getSemantics() == &APFloat::IEEEhalf ||
1243 &Val2.getSemantics() == &APFloat::IEEEsingle ||
1244 &Val2.getSemantics() == &APFloat::IEEEdouble ||
1245 &Val2.getSemantics() == &APFloat::PPCDoubleDouble;
1242 return &Val2.getSemantics() == &APFloat::IEEEhalf() ||
1243 &Val2.getSemantics() == &APFloat::IEEEsingle() ||
1244 &Val2.getSemantics() == &APFloat::IEEEdouble() ||
1245 &Val2.getSemantics() == &APFloat::PPCDoubleDouble();
12461246 }
12471247 }
12481248
26092609 llvm_unreachable("Accessor can only be used when element is float/double!");
26102610 case Type::HalfTyID: {
26112611 auto EltVal = *reinterpret_cast(EltPtr);
2612 return APFloat(APFloat::IEEEhalf, APInt(16, EltVal));
2612 return APFloat(APFloat::IEEEhalf(), APInt(16, EltVal));
26132613 }
26142614 case Type::FloatTyID: {
26152615 auto EltVal = *reinterpret_cast(EltPtr);
2616 return APFloat(APFloat::IEEEsingle, APInt(32, EltVal));
2616 return APFloat(APFloat::IEEEsingle(), APInt(32, EltVal));
26172617 }
26182618 case Type::DoubleTyID: {
26192619 auto EltVal = *reinterpret_cast(EltPtr);
2620 return APFloat(APFloat::IEEEdouble, APInt(64, EltVal));
2620 return APFloat(APFloat::IEEEdouble(), APInt(64, EltVal));
26212621 }
26222622 }
26232623 }
982982
983983 bool APFLosesInfo;
984984 APFloat APF = cFP->getValueAPF();
985 APF.convert(APFloat::IEEEdouble, APFloat::rmNearestTiesToEven, &APFLosesInfo);
985 APF.convert(APFloat::IEEEdouble(), APFloat::rmNearestTiesToEven, &APFLosesInfo);
986986 *LosesInfo = APFLosesInfo;
987987 return APF.convertToDouble();
988988 }
6767 };
6868
6969 struct DenseMapAPFloatKeyInfo {
70 static inline APFloat getEmptyKey() { return APFloat(APFloat::Bogus, 1); }
71 static inline APFloat getTombstoneKey() { return APFloat(APFloat::Bogus, 2); }
70 static inline APFloat getEmptyKey() { return APFloat(APFloat::Bogus(), 1); }
71 static inline APFloat getTombstoneKey() { return APFloat(APFloat::Bogus(), 2); }
7272 static unsigned getHashValue(const APFloat &Key) {
7373 return static_cast(hash_value(Key));
7474 }
40294029 if (ConstantFP *CFP0 =
40304030 mdconst::dyn_extract_or_null(MD->getOperand(0))) {
40314031 const APFloat &Accuracy = CFP0->getValueAPF();
4032 Assert(&Accuracy.getSemantics() == &APFloat::IEEEsingle,
4032 Assert(&Accuracy.getSemantics() == &APFloat::IEEEsingle(),
40334033 "fpmath accuracy must have float type", &I);
40344034 Assert(Accuracy.isFiniteNonZero() && !Accuracy.isNegative(),
40354035 "fpmath accuracy not a positive number!", &I);
10411041 return false;
10421042 }
10431043 case AsmToken::Real: {
1044 APFloat RealVal(APFloat::IEEEdouble, getTok().getString());
1044 APFloat RealVal(APFloat::IEEEdouble(), getTok().getString());
10451045 uint64_t IntVal = RealVal.bitcastToAPInt().getZExtValue();
10461046 Res = MCConstantExpr::create(IntVal, getContext());
10471047 EndLoc = Lexer.getTok().getEndLoc();
17601760 case DK_SINGLE:
17611761 case DK_FLOAT:
17621762 case DK_DC_S:
1763 return parseDirectiveRealValue(IDVal, APFloat::IEEEsingle);
1763 return parseDirectiveRealValue(IDVal, APFloat::IEEEsingle());
17641764 case DK_DOUBLE:
17651765 case DK_DC_D:
1766 return parseDirectiveRealValue(IDVal, APFloat::IEEEdouble);
1766 return parseDirectiveRealValue(IDVal, APFloat::IEEEdouble());
17671767 case DK_ALIGN: {
17681768 bool IsPow2 = !getContext().getAsmInfo()->getAlignmentIsInBytes();
17691769 return parseDirectiveAlign(IsPow2, /*ExprSize=*/1);
19421942 case DK_DCB_B:
19431943 return parseDirectiveDCB(IDVal, 1);
19441944 case DK_DCB_D:
1945 return parseDirectiveRealDCB(IDVal, APFloat::IEEEdouble);
1945 return parseDirectiveRealDCB(IDVal, APFloat::IEEEdouble());
19461946 case DK_DCB_L:
19471947 return parseDirectiveDCB(IDVal, 4);
19481948 case DK_DCB_S:
1949 return parseDirectiveRealDCB(IDVal, APFloat::IEEEsingle);
1949 return parseDirectiveRealDCB(IDVal, APFloat::IEEEsingle());
19501950 case DK_DC_X:
19511951 case DK_DCB_X:
19521952 return TokError(Twine(IDVal) +
5858 unsigned int sizeInBits;
5959 };
6060
61 const fltSemantics APFloatBase::IEEEhalf = {15, -14, 11, 16};
62 const fltSemantics APFloatBase::IEEEsingle = {127, -126, 24, 32};
63 const fltSemantics APFloatBase::IEEEdouble = {1023, -1022, 53, 64};
64 const fltSemantics APFloatBase::IEEEquad = {16383, -16382, 113, 128};
65 const fltSemantics APFloatBase::x87DoubleExtended = {16383, -16382, 64, 80};
66 const fltSemantics APFloatBase::Bogus = {0, 0, 0, 0};
61 static const fltSemantics semIEEEhalf = {15, -14, 11, 16};
62 static const fltSemantics semIEEEsingle = {127, -126, 24, 32};
63 static const fltSemantics semIEEEdouble = {1023, -1022, 53, 64};
64 static const fltSemantics semIEEEquad = {16383, -16382, 113, 128};
65 static const fltSemantics semX87DoubleExtended = {16383, -16382, 64, 80};
66 static const fltSemantics semBogus = {0, 0, 0, 0};
6767
6868 /* The PowerPC format consists of two doubles. It does not map cleanly
6969 onto the usual format above. It is approximated using twice the
7676 to represent all possible values held by a PPC double-double number,
7777 for example: (long double) 1.0 + (long double) 0x1p-106
7878 Should this be replaced by a full emulation of PPC double-double? */
79 const fltSemantics APFloatBase::PPCDoubleDouble = {0, 0, 0, 0};
79 static const fltSemantics semPPCDoubleDouble = {0, 0, 0, 0};
8080
8181 /* There are temporary semantics for the real PPCDoubleDouble implementation.
8282 Currently, APFloat of PPCDoubleDouble holds one PPCDoubleDoubleImpl as the
8686
8787 TODO: Once all functions support DoubleAPFloat mode, we'll change all
8888 PPCDoubleDoubleImpl to IEEEdouble and remove PPCDoubleDoubleImpl. */
89 static const fltSemantics PPCDoubleDoubleImpl = {1023, -1022 + 53, 53 + 53,
90 128};
89 static const fltSemantics semPPCDoubleDoubleImpl = {1023, -1022 + 53, 53 + 53,
90 128};
91
92 const fltSemantics &APFloatBase::IEEEhalf() {
93 return semIEEEhalf;
94 }
95 const fltSemantics &APFloatBase::IEEEsingle() {
96 return semIEEEsingle;
97 }
98 const fltSemantics &APFloatBase::IEEEdouble() {
99 return semIEEEdouble;
100 }
101 const fltSemantics &APFloatBase::IEEEquad() {
102 return semIEEEquad;
103 }
104 const fltSemantics &APFloatBase::x87DoubleExtended() {
105 return semX87DoubleExtended;
106 }
107 const fltSemantics &APFloatBase::Bogus() {
108 return semBogus;
109 }
110 const fltSemantics &APFloatBase::PPCDoubleDouble() {
111 return semPPCDoubleDouble;
112 }
91113
92114 /* A tight upper bound on number of parts required to hold the value
93115 pow(5, power) is
684706 // For x87 extended precision, we want to make a NaN, not a
685707 // pseudo-NaN. Maybe we should expose the ability to make
686708 // pseudo-NaNs?
687 if (semantics == &APFloat::x87DoubleExtended)
709 if (semantics == &semX87DoubleExtended)
688710 APInt::tcSetBit(significand, QNaNBit + 1);
689711 }
690712
709731 category = rhs.category;
710732 sign = rhs.sign;
711733
712 rhs.semantics = &Bogus;
734 rhs.semantics = &semBogus;
713735 return *this;
714736 }
715737
829851 assign(rhs);
830852 }
831853
832 IEEEFloat::IEEEFloat(IEEEFloat &&rhs) : semantics(&Bogus) {
854 IEEEFloat::IEEEFloat(IEEEFloat &&rhs) : semantics(&semBogus) {
833855 *this = std::move(rhs);
834856 }
835857
19281950 shift = toSemantics.precision - fromSemantics.precision;
19291951
19301952 bool X86SpecialNan = false;
1931 if (&fromSemantics == &IEEEFloat::x87DoubleExtended &&
1932 &toSemantics != &IEEEFloat::x87DoubleExtended && category == fcNaN &&
1953 if (&fromSemantics == &semX87DoubleExtended &&
1954 &toSemantics != &semX87DoubleExtended && category == fcNaN &&
19331955 (!(*significandParts() & 0x8000000000000000ULL) ||
19341956 !(*significandParts() & 0x4000000000000000ULL))) {
19351957 // x86 has some unusual NaNs which cannot be represented in any other
19932015
19942016 // For x87 extended precision, we want to make a NaN, not a special NaN if
19952017 // the input wasn't special either.
1996 if (!X86SpecialNan && semantics == &IEEEFloat::x87DoubleExtended)
2018 if (!X86SpecialNan && semantics == &semX87DoubleExtended)
19972019 APInt::tcSetBit(significandParts(), semantics->precision - 1);
19982020
19992021 // gcc forces the Quiet bit on, which means (float)(double)(float_sNan)
27952817 // the actual IEEE respresentations. We compensate for that here.
27962818
27972819 APInt IEEEFloat::convertF80LongDoubleAPFloatToAPInt() const {
2798 assert(semantics == (const llvm::fltSemantics*)&x87DoubleExtended);
2820 assert(semantics == (const llvm::fltSemantics*)&semX87DoubleExtended);
27992821 assert(partCount()==2);
28002822
28012823 uint64_t myexponent, mysignificand;
28252847 }
28262848
28272849 APInt IEEEFloat::convertPPCDoubleDoubleAPFloatToAPInt() const {
2828 assert(semantics == (const llvm::fltSemantics *)&PPCDoubleDoubleImpl);
2850 assert(semantics == (const llvm::fltSemantics *)&semPPCDoubleDoubleImpl);
28292851 assert(partCount()==2);
28302852
28312853 uint64_t words[2];
28392861 // Declare fltSemantics before APFloat that uses it (and
28402862 // saves pointer to it) to ensure correct destruction order.
28412863 fltSemantics extendedSemantics = *semantics;
2842 extendedSemantics.minExponent = IEEEdouble.minExponent;
2864 extendedSemantics.minExponent = semIEEEdouble.minExponent;
28432865 IEEEFloat extended(*this);
28442866 fs = extended.convert(extendedSemantics, rmNearestTiesToEven, &losesInfo);
28452867 assert(fs == opOK && !losesInfo);
28462868 (void)fs;
28472869
28482870 IEEEFloat u(extended);
2849 fs = u.convert(IEEEdouble, rmNearestTiesToEven, &losesInfo);
2871 fs = u.convert(semIEEEdouble, rmNearestTiesToEven, &losesInfo);
28502872 assert(fs == opOK || fs == opInexact);
28512873 (void)fs;
28522874 words[0] = *u.convertDoubleAPFloatToAPInt().getRawData();
28622884
28632885 IEEEFloat v(extended);
28642886 v.subtract(u, rmNearestTiesToEven);
2865 fs = v.convert(IEEEdouble, rmNearestTiesToEven, &losesInfo);
2887 fs = v.convert(semIEEEdouble, rmNearestTiesToEven, &losesInfo);
28662888 assert(fs == opOK && !losesInfo);
28672889 (void)fs;
28682890 words[1] = *v.convertDoubleAPFloatToAPInt().getRawData();
28742896 }
28752897
28762898 APInt IEEEFloat::convertQuadrupleAPFloatToAPInt() const {
2877 assert(semantics == (const llvm::fltSemantics*)&IEEEquad);
2899 assert(semantics == (const llvm::fltSemantics*)&semIEEEquad);
28782900 assert(partCount()==2);
28792901
28802902 uint64_t myexponent, mysignificand, mysignificand2;
29082930 }
29092931
29102932 APInt IEEEFloat::convertDoubleAPFloatToAPInt() const {
2911 assert(semantics == (const llvm::fltSemantics*)&IEEEdouble);
2933 assert(semantics == (const llvm::fltSemantics*)&semIEEEdouble);
29122934 assert(partCount()==1);
29132935
29142936 uint64_t myexponent, mysignificand;
29362958 }
29372959
29382960 APInt IEEEFloat::convertFloatAPFloatToAPInt() const {
2939 assert(semantics == (const llvm::fltSemantics*)&IEEEsingle);
2961 assert(semantics == (const llvm::fltSemantics*)&semIEEEsingle);
29402962 assert(partCount()==1);
29412963
29422964 uint32_t myexponent, mysignificand;
29632985 }
29642986
29652987 APInt IEEEFloat::convertHalfAPFloatToAPInt() const {
2966 assert(semantics == (const llvm::fltSemantics*)&IEEEhalf);
2988 assert(semantics == (const llvm::fltSemantics*)&semIEEEhalf);
29672989 assert(partCount()==1);
29682990
29692991 uint32_t myexponent, mysignificand;
29943016 // and treating the result as a normal integer is unlikely to be useful.
29953017
29963018 APInt IEEEFloat::bitcastToAPInt() const {
2997 if (semantics == (const llvm::fltSemantics*)&IEEEhalf)
3019 if (semantics == (const llvm::fltSemantics*)&semIEEEhalf)
29983020 return convertHalfAPFloatToAPInt();
29993021
3000 if (semantics == (const llvm::fltSemantics*)&IEEEsingle)
3022 if (semantics == (const llvm::fltSemantics*)&semIEEEsingle)
30013023 return convertFloatAPFloatToAPInt();
30023024
3003 if (semantics == (const llvm::fltSemantics*)&IEEEdouble)
3025 if (semantics == (const llvm::fltSemantics*)&semIEEEdouble)
30043026 return convertDoubleAPFloatToAPInt();
30053027
3006 if (semantics == (const llvm::fltSemantics*)&IEEEquad)
3028 if (semantics == (const llvm::fltSemantics*)&semIEEEquad)
30073029 return convertQuadrupleAPFloatToAPInt();
30083030
3009 if (semantics == (const llvm::fltSemantics *)&PPCDoubleDoubleImpl)
3031 if (semantics == (const llvm::fltSemantics *)&semPPCDoubleDoubleImpl)
30103032 return convertPPCDoubleDoubleAPFloatToAPInt();
30113033
3012 assert(semantics == (const llvm::fltSemantics*)&x87DoubleExtended &&
3034 assert(semantics == (const llvm::fltSemantics*)&semX87DoubleExtended &&
30133035 "unknown format!");
30143036 return convertF80LongDoubleAPFloatToAPInt();
30153037 }
30163038
30173039 float IEEEFloat::convertToFloat() const {
3018 assert(semantics == (const llvm::fltSemantics*)&IEEEsingle &&
3040 assert(semantics == (const llvm::fltSemantics*)&semIEEEsingle &&
30193041 "Float semantics are not IEEEsingle");
30203042 APInt api = bitcastToAPInt();
30213043 return api.bitsToFloat();
30223044 }
30233045
30243046 double IEEEFloat::convertToDouble() const {
3025 assert(semantics == (const llvm::fltSemantics*)&IEEEdouble &&
3047 assert(semantics == (const llvm::fltSemantics*)&semIEEEdouble &&
30263048 "Float semantics are not IEEEdouble");
30273049 APInt api = bitcastToAPInt();
30283050 return api.bitsToDouble();
30423064 uint64_t myexponent = (i2 & 0x7fff);
30433065 uint64_t mysignificand = i1;
30443066
3045 initialize(&IEEEFloat::x87DoubleExtended);
3067 initialize(&semX87DoubleExtended);
30463068 assert(partCount()==2);
30473069
30483070 sign = static_cast(i2>>15);
30763098
30773099 // Get the first double and convert to our format.
30783100 initFromDoubleAPInt(APInt(64, i1));
3079 fs = convert(PPCDoubleDoubleImpl, rmNearestTiesToEven, &losesInfo);
3101 fs = convert(semPPCDoubleDoubleImpl, rmNearestTiesToEven, &losesInfo);
30803102 assert(fs == opOK && !losesInfo);
30813103 (void)fs;
30823104
30833105 // Unless we have a special case, add in second double.
30843106 if (isFiniteNonZero()) {
3085 IEEEFloat v(IEEEdouble, APInt(64, i2));
3086 fs = v.convert(PPCDoubleDoubleImpl, rmNearestTiesToEven, &losesInfo);
3107 IEEEFloat v(semIEEEdouble, APInt(64, i2));
3108 fs = v.convert(semPPCDoubleDoubleImpl, rmNearestTiesToEven, &losesInfo);
30873109 assert(fs == opOK && !losesInfo);
30883110 (void)fs;
30893111
30993121 uint64_t mysignificand = i1;
31003122 uint64_t mysignificand2 = i2 & 0xffffffffffffLL;
31013123
3102 initialize(&IEEEFloat::IEEEquad);
3124 initialize(&semIEEEquad);
31033125 assert(partCount()==2);
31043126
31053127 sign = static_cast(i2>>63);
31353157 uint64_t myexponent = (i >> 52) & 0x7ff;
31363158 uint64_t mysignificand = i & 0xfffffffffffffLL;
31373159
3138 initialize(&IEEEFloat::IEEEdouble);
3160 initialize(&semIEEEdouble);
31393161 assert(partCount()==1);
31403162
31413163 sign = static_cast(i>>63);
31663188 uint32_t myexponent = (i >> 23) & 0xff;
31673189 uint32_t mysignificand = i & 0x7fffff;
31683190
3169 initialize(&IEEEFloat::IEEEsingle);
3191 initialize(&semIEEEsingle);
31703192 assert(partCount()==1);
31713193
31723194 sign = i >> 31;
31973219 uint32_t myexponent = (i >> 10) & 0x1f;
31983220 uint32_t mysignificand = i & 0x3ff;
31993221
3200 initialize(&IEEEFloat::IEEEhalf);
3222 initialize(&semIEEEhalf);
32013223 assert(partCount()==1);
32023224
32033225 sign = i >> 15;
32273249 /// isIEEE argument distinguishes between PPC128 and IEEE128 (not meaningful
32283250 /// when the size is anything else).
32293251 void IEEEFloat::initFromAPInt(const fltSemantics *Sem, const APInt &api) {
3230 if (Sem == &IEEEhalf)
3252 if (Sem == &semIEEEhalf)
32313253 return initFromHalfAPInt(api);
3232 if (Sem == &IEEEsingle)
3254 if (Sem == &semIEEEsingle)
32333255 return initFromFloatAPInt(api);
3234 if (Sem == &IEEEdouble)
3256 if (Sem == &semIEEEdouble)
32353257 return initFromDoubleAPInt(api);
3236 if (Sem == &x87DoubleExtended)
3258 if (Sem == &semX87DoubleExtended)
32373259 return initFromF80LongDoubleAPInt(api);
3238 if (Sem == &IEEEquad)
3260 if (Sem == &semIEEEquad)
32393261 return initFromQuadrupleAPInt(api);
3240 if (Sem == &PPCDoubleDoubleImpl)
3262 if (Sem == &semPPCDoubleDoubleImpl)
32413263 return initFromPPCDoubleDoubleAPInt(api);
32423264
32433265 llvm_unreachable(nullptr);
33003322 }
33013323
33023324 IEEEFloat::IEEEFloat(float f) {
3303 initFromAPInt(&IEEEsingle, APInt::floatToBits(f));
3325 initFromAPInt(&semIEEEsingle, APInt::floatToBits(f));
33043326 }
33053327
33063328 IEEEFloat::IEEEFloat(double d) {
3307 initFromAPInt(&IEEEdouble, APInt::doubleToBits(d));
3329 initFromAPInt(&semIEEEdouble, APInt::doubleToBits(d));
33083330 }
33093331
33103332 namespace {
38293851 }
38303852
38313853 DoubleAPFloat::DoubleAPFloat(const fltSemantics &S)
3832 : Semantics(&S), Floats(new APFloat[2]{APFloat(PPCDoubleDoubleImpl),
3833 APFloat(IEEEdouble)}) {
3834 assert(Semantics == &PPCDoubleDouble);
3854 : Semantics(&S), Floats(new APFloat[2]{APFloat(semPPCDoubleDoubleImpl),
3855 APFloat(semIEEEdouble)}) {
3856 assert(Semantics == &semPPCDoubleDouble);
38353857 }
38363858
38373859 DoubleAPFloat::DoubleAPFloat(const fltSemantics &S, uninitializedTag)
38383860 : Semantics(&S),
3839 Floats(new APFloat[2]{APFloat(PPCDoubleDoubleImpl, uninitialized),
3840 APFloat(IEEEdouble, uninitialized)}) {
3841 assert(Semantics == &PPCDoubleDouble);
3861 Floats(new APFloat[2]{APFloat(semPPCDoubleDoubleImpl, uninitialized),
3862 APFloat(semIEEEdouble, uninitialized)}) {
3863 assert(Semantics == &semPPCDoubleDouble);
38423864 }
38433865
38443866 DoubleAPFloat::DoubleAPFloat(const fltSemantics &S, integerPart I)
3845 : Semantics(&S), Floats(new APFloat[2]{APFloat(PPCDoubleDoubleImpl, I),
3846 APFloat(IEEEdouble)}) {
3847 assert(Semantics == &PPCDoubleDouble);
3867 : Semantics(&S), Floats(new APFloat[2]{APFloat(semPPCDoubleDoubleImpl, I),
3868 APFloat(semIEEEdouble)}) {
3869 assert(Semantics == &semPPCDoubleDouble);
38483870 }
38493871
38503872 DoubleAPFloat::DoubleAPFloat(const fltSemantics &S, const APInt &I)
38513873 : Semantics(&S), Floats(new APFloat[2]{
3852 APFloat(PPCDoubleDoubleImpl, I),
3853 APFloat(IEEEdouble, APInt(64, I.getRawData()[1]))}) {
3854 assert(Semantics == &PPCDoubleDouble);
3874 APFloat(semPPCDoubleDoubleImpl, I),
3875 APFloat(semIEEEdouble, APInt(64, I.getRawData()[1]))}) {
3876 assert(Semantics == &semPPCDoubleDouble);
38553877 }
38563878
38573879 DoubleAPFloat::DoubleAPFloat(const fltSemantics &S, APFloat &&First,
38583880 APFloat &&Second)
38593881 : Semantics(&S),
38603882 Floats(new APFloat[2]{std::move(First), std::move(Second)}) {
3861 assert(Semantics == &PPCDoubleDouble);
3883 assert(Semantics == &semPPCDoubleDouble);
38623884 // TODO Check for First == &IEEEdouble once the transition is done.
3863 assert(&Floats[0].getSemantics() == &PPCDoubleDoubleImpl ||
3864 &Floats[0].getSemantics() == &IEEEdouble);
3865 assert(&Floats[1].getSemantics() == &IEEEdouble);
3885 assert(&Floats[0].getSemantics() == &semPPCDoubleDoubleImpl ||
3886 &Floats[0].getSemantics() == &semIEEEdouble);
3887 assert(&Floats[1].getSemantics() == &semIEEEdouble);
38663888 }
38673889
38683890 DoubleAPFloat::DoubleAPFloat(const DoubleAPFloat &RHS)
38703892 Floats(RHS.Floats ? new APFloat[2]{APFloat(RHS.Floats[0]),
38713893 APFloat(RHS.Floats[1])}
38723894 : nullptr) {
3873 assert(Semantics == &PPCDoubleDouble);
3895 assert(Semantics == &semPPCDoubleDouble);
38743896 }
38753897
38763898 DoubleAPFloat::DoubleAPFloat(DoubleAPFloat &&RHS)
38773899 : Semantics(RHS.Semantics), Floats(std::move(RHS.Floats)) {
3878 RHS.Semantics = &Bogus;
3879 assert(Semantics == &PPCDoubleDouble);
3900 RHS.Semantics = &semBogus;
3901 assert(Semantics == &semPPCDoubleDouble);
38803902 }
38813903
38823904 DoubleAPFloat &DoubleAPFloat::operator=(const DoubleAPFloat &RHS) {
40084030
40094031 // These conversions will go away once PPCDoubleDoubleImpl goes away.
40104032 // (PPCDoubleDoubleImpl, IEEEDouble) -> (IEEEDouble, IEEEDouble)
4011 APFloat A(IEEEdouble,
4033 APFloat A(semIEEEdouble,
40124034 APInt(64, LHS.Floats[0].bitcastToAPInt().getRawData()[0])),
40134035 AA(LHS.Floats[1]),
4014 C(IEEEdouble, APInt(64, RHS.Floats[0].bitcastToAPInt().getRawData()[0])),
4036 C(semIEEEdouble, APInt(64, RHS.Floats[0].bitcastToAPInt().getRawData()[0])),
40154037 CC(RHS.Floats[1]);
4016 assert(&AA.getSemantics() == &IEEEdouble);
4017 assert(&CC.getSemantics() == &IEEEdouble);
4018 Out.Floats[0] = APFloat(IEEEdouble);
4019 assert(&Out.Floats[1].getSemantics() == &IEEEdouble);
4038 assert(&AA.getSemantics() == &semIEEEdouble);
4039 assert(&CC.getSemantics() == &semIEEEdouble);
4040 Out.Floats[0] = APFloat(semIEEEdouble);
4041 assert(&Out.Floats[1].getSemantics() == &semIEEEdouble);
40204042
40214043 auto Ret = Out.addImpl(A, AA, C, CC, RM);
40224044
40234045 // (IEEEDouble, IEEEDouble) -> (PPCDoubleDoubleImpl, IEEEDouble)
40244046 uint64_t Buffer[] = {Out.Floats[0].bitcastToAPInt().getRawData()[0],
40254047 Out.Floats[1].bitcastToAPInt().getRawData()[0]};
4026 Out.Floats[0] = APFloat(PPCDoubleDoubleImpl, APInt(128, 2, Buffer));
4048 Out.Floats[0] = APFloat(semPPCDoubleDoubleImpl, APInt(128, 2, Buffer));
40274049 return Ret;
40284050 }
40294051
40904112 } else if (usesLayout(Semantics)) {
40914113 new (&Double)
40924114 DoubleAPFloat(Semantics, APFloat(std::move(F), F.getSemantics()),
4093 APFloat(IEEEdouble));
4115 APFloat(semIEEEdouble));
40944116 } else {
40954117 llvm_unreachable("Unexpected semantics");
40964118 }
41164138 return U.IEEE.convert(ToSemantics, RM, losesInfo);
41174139 } else if (usesLayout(getSemantics()) &&
41184140 usesLayout(ToSemantics)) {
4119 assert(&ToSemantics == &PPCDoubleDouble);
4120 auto Ret = U.IEEE.convert(PPCDoubleDoubleImpl, RM, losesInfo);
4141 assert(&ToSemantics == &semPPCDoubleDouble);
4142 auto Ret = U.IEEE.convert(semPPCDoubleDoubleImpl, RM, losesInfo);
41214143 *this = APFloat(
4122 DoubleAPFloat(PPCDoubleDouble, std::move(*this), APFloat(IEEEdouble)),
4144 DoubleAPFloat(semPPCDoubleDouble, std::move(*this), APFloat(semIEEEdouble)),
41234145 ToSemantics);
41244146 return Ret;
41254147 } else if (usesLayout(getSemantics()) &&
41364158 if (isIEEE) {
41374159 switch (BitWidth) {
41384160 case 16:
4139 return APFloat(IEEEhalf, APInt::getAllOnesValue(BitWidth));
4161 return APFloat(semIEEEhalf, APInt::getAllOnesValue(BitWidth));
41404162 case 32:
4141 return APFloat(IEEEsingle, APInt::getAllOnesValue(BitWidth));
4163 return APFloat(semIEEEsingle, APInt::getAllOnesValue(BitWidth));
41424164 case 64:
4143 return APFloat(IEEEdouble, APInt::getAllOnesValue(BitWidth));
4165 return APFloat(semIEEEdouble, APInt::getAllOnesValue(BitWidth));
41444166 case 80:
4145 return APFloat(x87DoubleExtended, APInt::getAllOnesValue(BitWidth));
4167 return APFloat(semX87DoubleExtended, APInt::getAllOnesValue(BitWidth));
41464168 case 128:
4147 return APFloat(IEEEquad, APInt::getAllOnesValue(BitWidth));
4169 return APFloat(semIEEEquad, APInt::getAllOnesValue(BitWidth));
41484170 default:
41494171 llvm_unreachable("Unknown floating bit width");
41504172 }
41514173 } else {
41524174 assert(BitWidth == 128);
4153 return APFloat(PPCDoubleDouble, APInt::getAllOnesValue(BitWidth));
4175 return APFloat(semPPCDoubleDouble, APInt::getAllOnesValue(BitWidth));
41544176 }
41554177 }
41564178
182182
183183 // Build the float and print it.
184184 uint64_t RawBits[2] = {D, AdjustedE};
185 APFloat Float(APFloat::x87DoubleExtended, APInt(80, RawBits));
185 APFloat Float(APFloat::x87DoubleExtended(), APInt(80, RawBits));
186186 SmallVector Chars;
187187 Float.toString(Chars, Precision, 0);
188188 return std::string(Chars.begin(), Chars.end());
22052205
22062206 const AsmToken &Tok = Parser.getTok();
22072207 if (Tok.is(AsmToken::Real)) {
2208 APFloat RealVal(APFloat::IEEEdouble, Tok.getString());
2208 APFloat RealVal(APFloat::IEEEdouble(), Tok.getString());
22092209 if (isNegative)
22102210 RealVal.changeSign();
22112211
22312231 return MatchOperand_ParseFail;
22322232 }
22332233 } else {
2234 APFloat RealVal(APFloat::IEEEdouble, Tok.getString());
2234 APFloat RealVal(APFloat::IEEEdouble(), Tok.getString());
22352235 uint64_t IntVal = RealVal.bitcastToAPInt().getZExtValue();
22362236 // If we had a '-' in front, toggle the sign bit.
22372237 IntVal ^= (uint64_t)isNegative << 63;
31533153 // so convert the value.
31543154 const AsmToken &Tok = Parser.getTok();
31553155 if (Tok.is(AsmToken::Real)) {
3156 APFloat RealVal(APFloat::IEEEdouble, Tok.getString());
3156 APFloat RealVal(APFloat::IEEEdouble(), Tok.getString());
31573157 uint64_t IntVal = RealVal.bitcastToAPInt().getZExtValue();
31583158 if (Mnemonic != "fcmp" && Mnemonic != "fcmpe" && Mnemonic != "fcmeq" &&
31593159 Mnemonic != "fcmge" && Mnemonic != "fcmgt" && Mnemonic != "fcmle" &&
16131613
16141614 assert(Op.getValueType() == MVT::f64);
16151615
1616 APFloat C1Val(APFloat::IEEEdouble, "0x1.0p+52");
1616 APFloat C1Val(APFloat::IEEEdouble(), "0x1.0p+52");
16171617 SDValue C1 = DAG.getConstantFP(C1Val, SL, MVT::f64);
16181618 SDValue CopySign = DAG.getNode(ISD::FCOPYSIGN, SL, MVT::f64, C1, Src);
16191619
16241624
16251625 SDValue Fabs = DAG.getNode(ISD::FABS, SL, MVT::f64, Src);
16261626
1627 APFloat C2Val(APFloat::IEEEdouble, "0x1.fffffffffffffp+51");
1627 APFloat C2Val(APFloat::IEEEdouble(), "0x1.fffffffffffffp+51");
16281628 SDValue C2 = DAG.getConstantFP(C2Val, SL, MVT::f64);
16291629
16301630 EVT SetCCVT =
881881 static const fltSemantics *getFltSemantics(unsigned Size) {
882882 switch (Size) {
883883 case 4:
884 return &APFloat::IEEEsingle;
884 return &APFloat::IEEEsingle();
885885 case 8:
886 return &APFloat::IEEEdouble;
886 return &APFloat::IEEEdouble();
887887 case 2:
888 return &APFloat::IEEEhalf;
888 return &APFloat::IEEEhalf();
889889 default:
890890 llvm_unreachable("unsupported fp type");
891891 }
934934 AsmParser->hasInv2PiInlineImm());
935935 }
936936
937 APFloat FPLiteral(APFloat::IEEEdouble, APInt(64, Imm.Val));
937 APFloat FPLiteral(APFloat::IEEEdouble(), APInt(64, Imm.Val));
938938 if (!canLosslesslyConvertToFPType(FPLiteral, type))
939939 return false;
940940
992992 return false;
993993 }
994994
995 APFloat FPLiteral(APFloat::IEEEdouble, APInt(64, Imm.Val));
995 APFloat FPLiteral(APFloat::IEEEdouble(), APInt(64, Imm.Val));
996996 return canLosslesslyConvertToFPType(FPLiteral, type);
997997 }
998998
10611061 case 4:
10621062 case 2: {
10631063 bool lost;
1064 APFloat FPLiteral(APFloat::IEEEdouble, Literal);
1064 APFloat FPLiteral(APFloat::IEEEdouble(), Literal);
10651065 // Convert literal to single precision
10661066 FPLiteral.convert(*getFltSemantics(OpSize),
10671067 APFloat::rmNearestTiesToEven, &lost);
11291129 }
11301130
11311131 bool Lost;
1132 APFloat FPLiteral(APFloat::IEEEdouble, Literal);
1132 APFloat FPLiteral(APFloat::IEEEdouble(), Literal);
11331133 FPLiteral.convert(*getFltSemantics(Bitwidth / 8),
11341134 APFloat::rmNearestTiesToEven, &Lost);
11351135 Inst.addOperand(MCOperand::createImm(FPLiteral.bitcastToAPInt().getZExtValue()));
9898 case MachineOperand::MO_FPImmediate: {
9999 APFloat Val = MO.getFPImm()->getValueAPF();
100100 bool ignored;
101 Val.convert(APFloat::IEEEdouble, APFloat::rmTowardZero, &ignored);
101 Val.convert(APFloat::IEEEdouble(), APFloat::rmTowardZero, &ignored);
102102 MCOp = MCOperand::createFPImm(Val.convertToDouble());
103103 break;
104104 }
52945294 const AsmToken &Tok = Parser.getTok();
52955295 SMLoc Loc = Tok.getLoc();
52965296 if (Tok.is(AsmToken::Real) && isVmovf) {
5297 APFloat RealVal(APFloat::IEEEsingle, Tok.getString());
5297 APFloat RealVal(APFloat::IEEEsingle(), Tok.getString());
52985298 uint64_t IntVal = RealVal.bitcastToAPInt().getZExtValue();
52995299 // If we had a '-' in front, toggle the sign bit.
53005300 IntVal ^= (uint64_t)isNegative << 31;
17221722 if (Fp->getType()->getTypeID() == Type::FloatTyID) {
17231723 numHex = 8;
17241724 lead = "0f";
1725 APF.convert(APFloat::IEEEsingle, APFloat::rmNearestTiesToEven, &ignored);
1725 APF.convert(APFloat::IEEEsingle(), APFloat::rmNearestTiesToEven, &ignored);
17261726 } else if (Fp->getType()->getTypeID() == Type::DoubleTyID) {
17271727 numHex = 16;
17281728 lead = "0d";
1729 APF.convert(APFloat::IEEEdouble, APFloat::rmNearestTiesToEven, &ignored);
1729 APF.convert(APFloat::IEEEdouble(), APFloat::rmNearestTiesToEven, &ignored);
17301730 } else
17311731 llvm_unreachable("unsupported fp type");
17321732
738738
739739 // Constant 1.0f
740740 def FloatConst1 : PatLeaf<(fpimm), [{
741 return &N->getValueAPF().getSemantics() == &llvm::APFloat::IEEEsingle &&
741 return &N->getValueAPF().getSemantics() == &llvm::APFloat::IEEEsingle() &&
742742 N->getValueAPF().convertToFloat() == 1.0f;
743743 }]>;
744744 // Constant 1.0 (double)
745745 def DoubleConst1 : PatLeaf<(fpimm), [{
746 return &N->getValueAPF().getSemantics() == &llvm::APFloat::IEEEdouble &&
746 return &N->getValueAPF().getSemantics() == &llvm::APFloat::IEEEdouble() &&
747747 N->getValueAPF().convertToDouble() == 1.0;
748748 }]>;
749749
2929 case VK_NVPTX_SINGLE_PREC_FLOAT:
3030 OS << "0f";
3131 NumHex = 8;
32 APF.convert(APFloat::IEEEsingle, APFloat::rmNearestTiesToEven, &Ignored);
32 APF.convert(APFloat::IEEEsingle(), APFloat::rmNearestTiesToEven, &Ignored);
3333 break;
3434 case VK_NVPTX_DOUBLE_PREC_FLOAT:
3535 OS << "0d";
3636 NumHex = 16;
37 APF.convert(APFloat::IEEEdouble, APFloat::rmNearestTiesToEven, &Ignored);
37 APF.convert(APFloat::IEEEdouble(), APFloat::rmNearestTiesToEven, &Ignored);
3838 break;
3939 }
4040
598598 setOperationAction(ISD::UNDEF, MVT::f80, Expand);
599599 setOperationAction(ISD::FCOPYSIGN, MVT::f80, Expand);
600600 {
601 APFloat TmpFlt = APFloat::getZero(APFloat::x87DoubleExtended);
601 APFloat TmpFlt = APFloat::getZero(APFloat::x87DoubleExtended());
602602 addLegalFPImmediate(TmpFlt); // FLD0
603603 TmpFlt.changeSign();
604604 addLegalFPImmediate(TmpFlt); // FLD0/FCHS
605605
606606 bool ignored;
607607 APFloat TmpFlt2(+1.0);
608 TmpFlt2.convert(APFloat::x87DoubleExtended, APFloat::rmNearestTiesToEven,
608 TmpFlt2.convert(APFloat::x87DoubleExtended(), APFloat::rmNearestTiesToEven,
609609 &ignored);
610610 addLegalFPImmediate(TmpFlt2); // FLD1
611611 TmpFlt2.changeSign();
47664766 Ops.push_back(DAG.getConstant(V.trunc(32), dl, EltVT));
47674767 Ops.push_back(DAG.getConstant(V.lshr(32).trunc(32), dl, EltVT));
47684768 } else if (EltVT == MVT::f32) {
4769 APFloat FV(APFloat::IEEEsingle, V);
4769 APFloat FV(APFloat::IEEEsingle(), V);
47704770 Ops.push_back(DAG.getConstantFP(FV, dl, EltVT));
47714771 } else if (EltVT == MVT::f64) {
4772 APFloat FV(APFloat::IEEEdouble, V);
4772 APFloat FV(APFloat::IEEEdouble(), V);
47734773 Ops.push_back(DAG.getConstantFP(FV, dl, EltVT));
47744774 } else {
47754775 Ops.push_back(DAG.getConstant(V, dl, EltVT));
1437714377
1437814378 SmallVector CV1;
1437914379 CV1.push_back(
14380 ConstantFP::get(*Context, APFloat(APFloat::IEEEdouble,
14380 ConstantFP::get(*Context, APFloat(APFloat::IEEEdouble(),
1438114381 APInt(64, 0x4330000000000000ULL))));
1438214382 CV1.push_back(
14383 ConstantFP::get(*Context, APFloat(APFloat::IEEEdouble,
14383 ConstantFP::get(*Context, APFloat(APFloat::IEEEdouble(),
1438414384 APInt(64, 0x4530000000000000ULL))));
1438514385 Constant *C1 = ConstantVector::get(CV1);
1438614386 SDValue CPIdx1 = DAG.getConstantPool(C1, PtrVT, 16);
1458214582
1458314583 // Create the vector constant for -(0x1.0p39f + 0x1.0p23f).
1458414584 SDValue VecCstFAdd = DAG.getConstantFP(
14585 APFloat(APFloat::IEEEsingle, APInt(32, 0xD3000080)), DL, VecFloatVT);
14585 APFloat(APFloat::IEEEsingle(), APInt(32, 0xD3000080)), DL, VecFloatVT);
1458614586
1458714587 // float4 fhi = (float4) hi - (0x1.0p39f + 0x1.0p23f);
1458814588 SDValue HighBitcast = DAG.getBitcast(VecFloatVT, High);
1482014820 // For X87 we'd like to use the smallest FP type for this constant, but
1482114821 // for DAG type consistency we have to match the FP operand type.
1482214822
14823 APFloat Thresh(APFloat::IEEEsingle, APInt(32, 0x5f000000));
14823 APFloat Thresh(APFloat::IEEEsingle(), APInt(32, 0x5f000000));
1482414824 LLVM_ATTRIBUTE_UNUSED APFloat::opStatus Status = APFloat::opOK;
1482514825 bool LosesInfo = false;
1482614826 if (TheVT == MVT::f64)
1482714827 // The rounding mode is irrelevant as the conversion should be exact.
14828 Status = Thresh.convert(APFloat::IEEEdouble, APFloat::rmNearestTiesToEven,
14828 Status = Thresh.convert(APFloat::IEEEdouble(), APFloat::rmNearestTiesToEven,
1482914829 &LosesInfo);
1483014830 else if (TheVT == MVT::f80)
14831 Status = Thresh.convert(APFloat::x87DoubleExtended,
14831 Status = Thresh.convert(APFloat::x87DoubleExtended(),
1483214832 APFloat::rmNearestTiesToEven, &LosesInfo);
1483314833
1483414834 assert(Status == APFloat::opOK && !LosesInfo &&
1537815378 APInt MaskElt =
1537915379 IsFABS ? APInt::getSignedMaxValue(EltBits) : APInt::getSignBit(EltBits);
1538015380 const fltSemantics &Sem =
15381 EltVT == MVT::f64 ? APFloat::IEEEdouble :
15382 (IsF128 ? APFloat::IEEEquad : APFloat::IEEEsingle);
15381 EltVT == MVT::f64 ? APFloat::IEEEdouble() :
15382 (IsF128 ? APFloat::IEEEquad() : APFloat::IEEEsingle());
1538315383 SDValue Mask = DAG.getConstantFP(APFloat(Sem, MaskElt), dl, LogicVT);
1538415384
1538515385 SDValue Op0 = Op.getOperand(0);
1542315423
1542415424 MVT EltVT = VT.getScalarType();
1542515425 const fltSemantics &Sem =
15426 EltVT == MVT::f64 ? APFloat::IEEEdouble
15427 : (IsF128 ? APFloat::IEEEquad : APFloat::IEEEsingle);
15426 EltVT == MVT::f64 ? APFloat::IEEEdouble()
15427 : (IsF128 ? APFloat::IEEEquad() : APFloat::IEEEsingle());
1542815428
1542915429 // Perform all scalar logic operations as 16-byte vectors because there are no
1543015430 // scalar FP logic instructions in SSE.
12381238 if (CFP->getType() == Type::getPPC_FP128Ty(V->getContext()))
12391239 return V; // No constant folding of this.
12401240 // See if the value can be truncated to half and then reextended.
1241 if (Value *V = fitsInFPType(CFP, APFloat::IEEEhalf))
1241 if (Value *V = fitsInFPType(CFP, APFloat::IEEEhalf()))
12421242 return V;
12431243 // See if the value can be truncated to float and then reextended.
1244 if (Value *V = fitsInFPType(CFP, APFloat::IEEEsingle))
1244 if (Value *V = fitsInFPType(CFP, APFloat::IEEEsingle()))
12451245 return V;
12461246 if (CFP->getType()->isDoubleTy())
12471247 return V; // Won't shrink.
1248 if (Value *V = fitsInFPType(CFP, APFloat::IEEEdouble))
1248 if (Value *V = fitsInFPType(CFP, APFloat::IEEEdouble()))
12491249 return V;
12501250 // Don't try to shrink to various long double types.
12511251 }
46604660 const fltSemantics *Sem;
46614661 // FIXME: This shouldn't be here.
46624662 if (LHSExt->getSrcTy()->isHalfTy())
4663 Sem = &APFloat::IEEEhalf;
4663 Sem = &APFloat::IEEEhalf();
46644664 else if (LHSExt->getSrcTy()->isFloatTy())
4665 Sem = &APFloat::IEEEsingle;
4665 Sem = &APFloat::IEEEsingle();
46664666 else if (LHSExt->getSrcTy()->isDoubleTy())
4667 Sem = &APFloat::IEEEdouble;
4667 Sem = &APFloat::IEEEdouble();
46684668 else if (LHSExt->getSrcTy()->isFP128Ty())
4669 Sem = &APFloat::IEEEquad;
4669 Sem = &APFloat::IEEEquad();
46704670 else if (LHSExt->getSrcTy()->isX86_FP80Ty())
4671 Sem = &APFloat::x87DoubleExtended;
4671 Sem = &APFloat::x87DoubleExtended();
46724672 else if (LHSExt->getSrcTy()->isPPC_FP128Ty())
4673 Sem = &APFloat::PPCDoubleDouble;
4673 Sem = &APFloat::PPCDoubleDouble();
46744674 else
46754675 break;
46764676
899899 if (ConstantFP *Const = dyn_cast(Val)) {
900900 APFloat F = Const->getValueAPF();
901901 bool losesInfo;
902 (void)F.convert(APFloat::IEEEsingle, APFloat::rmNearestTiesToEven,
902 (void)F.convert(APFloat::IEEEsingle(), APFloat::rmNearestTiesToEven,
903903 &losesInfo);
904904 if (!losesInfo)
905905 return ConstantFP::get(Const->getContext(), F);
11281128 // We cannot readily convert a non-double type (like float) to a double.
11291129 // So we first convert V to something which could be converted to double.
11301130 bool ignored;
1131 V.convert(APFloat::IEEEdouble, APFloat::rmTowardZero, &ignored);
1131 V.convert(APFloat::IEEEdouble(), APFloat::rmTowardZero, &ignored);
11321132
11331133 // TODO: Should the new instructions propagate the 'fast' flag of the pow()?
11341134 Value *FMul = getPow(InnerChain, V.convertToDouble(), B);
3838 // positive/negative distinction is included only since the getQNaN/getSNaN
3939 // API provides the option.
4040 APInt payload = APInt::getOneBitSet(4, 2);
41 EXPECT_FALSE(APFloat::getQNaN(APFloat::IEEEsingle, false).isSignaling());
42 EXPECT_FALSE(APFloat::getQNaN(APFloat::IEEEsingle, true).isSignaling());
43 EXPECT_FALSE(APFloat::getQNaN(APFloat::IEEEsingle, false, &payload).isSignaling());
44 EXPECT_FALSE(APFloat::getQNaN(APFloat::IEEEsingle, true, &payload).isSignaling());
45 EXPECT_TRUE(APFloat::getSNaN(APFloat::IEEEsingle, false).isSignaling());
46 EXPECT_TRUE(APFloat::getSNaN(APFloat::IEEEsingle, true).isSignaling());
47 EXPECT_TRUE(APFloat::getSNaN(APFloat::IEEEsingle, false, &payload).isSignaling());
48 EXPECT_TRUE(APFloat::getSNaN(APFloat::IEEEsingle, true, &payload).isSignaling());
41 EXPECT_FALSE(APFloat::getQNaN(APFloat::IEEEsingle(), false).isSignaling());
42 EXPECT_FALSE(APFloat::getQNaN(APFloat::IEEEsingle(), true).isSignaling());
43 EXPECT_FALSE(APFloat::getQNaN(APFloat::IEEEsingle(), false, &payload).isSignaling());
44 EXPECT_FALSE(APFloat::getQNaN(APFloat::IEEEsingle(), true, &payload).isSignaling());
45 EXPECT_TRUE(APFloat::getSNaN(APFloat::IEEEsingle(), false).isSignaling());
46 EXPECT_TRUE(APFloat::getSNaN(APFloat::IEEEsingle(), true).isSignaling());
47 EXPECT_TRUE(APFloat::getSNaN(APFloat::IEEEsingle(), false, &payload).isSignaling());
48 EXPECT_TRUE(APFloat::getSNaN(APFloat::IEEEsingle(), true, &payload).isSignaling());
4949 }
5050
5151 TEST(APFloatTest, next) {
5252
53 APFloat test(APFloat::IEEEquad, APFloat::uninitialized);
54 APFloat expected(APFloat::IEEEquad, APFloat::uninitialized);
53 APFloat test(APFloat::IEEEquad(), APFloat::uninitialized);
54 APFloat expected(APFloat::IEEEquad(), APFloat::uninitialized);
5555
5656 // 1. Test Special Cases Values.
5757 //
6969 // 10. -0
7070
7171 // nextUp(+inf) = +inf.
72 test = APFloat::getInf(APFloat::IEEEquad, false);
73 expected = APFloat::getInf(APFloat::IEEEquad, false);
72 test = APFloat::getInf(APFloat::IEEEquad(), false);
73 expected = APFloat::getInf(APFloat::IEEEquad(), false);
7474 EXPECT_EQ(test.next(false), APFloat::opOK);
7575 EXPECT_TRUE(test.isInfinity());
7676 EXPECT_TRUE(!test.isNegative());
7777 EXPECT_TRUE(test.bitwiseIsEqual(expected));
7878
7979 // nextDown(+inf) = -nextUp(-inf) = -(-getLargest()) = getLargest()
80 test = APFloat::getInf(APFloat::IEEEquad, false);
81 expected = APFloat::getLargest(APFloat::IEEEquad, false);
80 test = APFloat::getInf(APFloat::IEEEquad(), false);
81 expected = APFloat::getLargest(APFloat::IEEEquad(), false);
8282 EXPECT_EQ(test.next(true), APFloat::opOK);
8383 EXPECT_TRUE(!test.isNegative());
8484 EXPECT_TRUE(test.bitwiseIsEqual(expected));
8585
8686 // nextUp(-inf) = -getLargest()
87 test = APFloat::getInf(APFloat::IEEEquad, true);
88 expected = APFloat::getLargest(APFloat::IEEEquad, true);
87 test = APFloat::getInf(APFloat::IEEEquad(), true);
88 expected = APFloat::getLargest(APFloat::IEEEquad(), true);
8989 EXPECT_EQ(test.next(false), APFloat::opOK);
9090 EXPECT_TRUE(test.isNegative());
9191 EXPECT_TRUE(test.bitwiseIsEqual(expected));
9292
9393 // nextDown(-inf) = -nextUp(+inf) = -(+inf) = -inf.
94 test = APFloat::getInf(APFloat::IEEEquad, true);
95 expected = APFloat::getInf(APFloat::IEEEquad, true);
94 test = APFloat::getInf(APFloat::IEEEquad(), true);
95 expected = APFloat::getInf(APFloat::IEEEquad(), true);
9696 EXPECT_EQ(test.next(true), APFloat::opOK);
9797 EXPECT_TRUE(test.isInfinity() && test.isNegative());
9898 EXPECT_TRUE(test.bitwiseIsEqual(expected));
9999
100100 // nextUp(getLargest()) = +inf
101 test = APFloat::getLargest(APFloat::IEEEquad, false);
102 expected = APFloat::getInf(APFloat::IEEEquad, false);
101 test = APFloat::getLargest(APFloat::IEEEquad(), false);
102 expected = APFloat::getInf(APFloat::IEEEquad(), false);
103103 EXPECT_EQ(test.next(false), APFloat::opOK);
104104 EXPECT_TRUE(test.isInfinity() && !test.isNegative());
105105 EXPECT_TRUE(test.bitwiseIsEqual(expected));
107107 // nextDown(getLargest()) = -nextUp(-getLargest())
108108 // = -(-getLargest() + inc)
109109 // = getLargest() - inc.
110 test = APFloat::getLargest(APFloat::IEEEquad, false);
111 expected = APFloat(APFloat::IEEEquad,
110 test = APFloat::getLargest(APFloat::IEEEquad(), false);
111 expected = APFloat(APFloat::IEEEquad(),
112112 "0x1.fffffffffffffffffffffffffffep+16383");
113113 EXPECT_EQ(test.next(true), APFloat::opOK);
114114 EXPECT_TRUE(!test.isInfinity() && !test.isNegative());
115115 EXPECT_TRUE(test.bitwiseIsEqual(expected));
116116
117117 // nextUp(-getLargest()) = -getLargest() + inc.
118 test = APFloat::getLargest(APFloat::IEEEquad, true);
119 expected = APFloat(APFloat::IEEEquad,
118 test = APFloat::getLargest(APFloat::IEEEquad(), true);
119 expected = APFloat(APFloat::IEEEquad(),
120120 "-0x1.fffffffffffffffffffffffffffep+16383");
121121 EXPECT_EQ(test.next(false), APFloat::opOK);
122122 EXPECT_TRUE(test.bitwiseIsEqual(expected));
123123
124124 // nextDown(-getLargest()) = -nextUp(getLargest()) = -(inf) = -inf.
125 test = APFloat::getLargest(APFloat::IEEEquad, true);
126 expected = APFloat::getInf(APFloat::IEEEquad, true);
125 test = APFloat::getLargest(APFloat::IEEEquad(), true);
126 expected = APFloat::getInf(APFloat::IEEEquad(), true);
127127 EXPECT_EQ(test.next(true), APFloat::opOK);
128128 EXPECT_TRUE(test.isInfinity() && test.isNegative());
129129 EXPECT_TRUE(test.bitwiseIsEqual(expected));
130130
131131 // nextUp(getSmallest()) = getSmallest() + inc.
132 test = APFloat(APFloat::IEEEquad, "0x0.0000000000000000000000000001p-16382");
133 expected = APFloat(APFloat::IEEEquad,
132 test = APFloat(APFloat::IEEEquad(), "0x0.0000000000000000000000000001p-16382");
133 expected = APFloat(APFloat::IEEEquad(),
134134 "0x0.0000000000000000000000000002p-16382");
135135 EXPECT_EQ(test.next(false), APFloat::opOK);
136136 EXPECT_TRUE(test.bitwiseIsEqual(expected));
137137
138138 // nextDown(getSmallest()) = -nextUp(-getSmallest()) = -(-0) = +0.
139 test = APFloat(APFloat::IEEEquad, "0x0.0000000000000000000000000001p-16382");
140 expected = APFloat::getZero(APFloat::IEEEquad, false);
139 test = APFloat(APFloat::IEEEquad(), "0x0.0000000000000000000000000001p-16382");
140 expected = APFloat::getZero(APFloat::IEEEquad(), false);
141141 EXPECT_EQ(test.next(true), APFloat::opOK);
142142 EXPECT_TRUE(test.isPosZero());
143143 EXPECT_TRUE(test.bitwiseIsEqual(expected));
144144
145145 // nextUp(-getSmallest()) = -0.
146 test = APFloat(APFloat::IEEEquad, "-0x0.0000000000000000000000000001p-16382");
147 expected = APFloat::getZero(APFloat::IEEEquad, true);
146 test = APFloat(APFloat::IEEEquad(), "-0x0.0000000000000000000000000001p-16382");
147 expected = APFloat::getZero(APFloat::IEEEquad(), true);
148148 EXPECT_EQ(test.next(false), APFloat::opOK);
149149 EXPECT_TRUE(test.isNegZero());
150150 EXPECT_TRUE(test.bitwiseIsEqual(expected));
151151
152152 // nextDown(-getSmallest()) = -nextUp(getSmallest()) = -getSmallest() - inc.
153 test = APFloat(APFloat::IEEEquad, "-0x0.0000000000000000000000000001p-16382");
154 expected = APFloat(APFloat::IEEEquad,
153 test = APFloat(APFloat::IEEEquad(), "-0x0.0000000000000000000000000001p-16382");
154 expected = APFloat(APFloat::IEEEquad(),
155155 "-0x0.0000000000000000000000000002p-16382");
156156 EXPECT_EQ(test.next(true), APFloat::opOK);
157157 EXPECT_TRUE(test.bitwiseIsEqual(expected));
158158
159159 // nextUp(qNaN) = qNaN
160 test = APFloat::getQNaN(APFloat::IEEEquad, false);
161 expected = APFloat::getQNaN(APFloat::IEEEquad, false);
160 test = APFloat::getQNaN(APFloat::IEEEquad(), false);
161 expected = APFloat::getQNaN(APFloat::IEEEquad(), false);
162162 EXPECT_EQ(test.next(false), APFloat::opOK);
163163 EXPECT_TRUE(test.bitwiseIsEqual(expected));
164164
165165 // nextDown(qNaN) = qNaN
166 test = APFloat::getQNaN(APFloat::IEEEquad, false);
167 expected = APFloat::getQNaN(APFloat::IEEEquad, false);
166 test = APFloat::getQNaN(APFloat::IEEEquad(), false);
167 expected = APFloat::getQNaN(APFloat::IEEEquad(), false);
168168 EXPECT_EQ(test.next(true), APFloat::opOK);
169169 EXPECT_TRUE(test.bitwiseIsEqual(expected));
170170
171171 // nextUp(sNaN) = qNaN
172 test = APFloat::getSNaN(APFloat::IEEEquad, false);
173 expected = APFloat::getQNaN(APFloat::IEEEquad, false);
172 test = APFloat::getSNaN(APFloat::IEEEquad(), false);
173 expected = APFloat::getQNaN(APFloat::IEEEquad(), false);
174174 EXPECT_EQ(test.next(false), APFloat::opInvalidOp);
175175 EXPECT_TRUE(test.bitwiseIsEqual(expected));
176176
177177 // nextDown(sNaN) = qNaN
178 test = APFloat::getSNaN(APFloat::IEEEquad, false);
179 expected = APFloat::getQNaN(APFloat::IEEEquad, false);
178 test = APFloat::getSNaN(APFloat::IEEEquad(), false);
179 expected = APFloat::getQNaN(APFloat::IEEEquad(), false);
180180 EXPECT_EQ(test.next(true), APFloat::opInvalidOp);
181181 EXPECT_TRUE(test.bitwiseIsEqual(expected));
182182
183183 // nextUp(+0) = +getSmallest()
184 test = APFloat::getZero(APFloat::IEEEquad, false);
185 expected = APFloat::getSmallest(APFloat::IEEEquad, false);
184 test = APFloat::getZero(APFloat::IEEEquad(), false);
185 expected = APFloat::getSmallest(APFloat::IEEEquad(), false);
186186 EXPECT_EQ(test.next(false), APFloat::opOK);
187187 EXPECT_TRUE(test.bitwiseIsEqual(expected));
188188
189189 // nextDown(+0) = -nextUp(-0) = -getSmallest()
190 test = APFloat::getZero(APFloat::IEEEquad, false);
191 expected = APFloat::getSmallest(APFloat::IEEEquad, true);
190 test = APFloat::getZero(APFloat::IEEEquad(), false);
191 expected = APFloat::getSmallest(APFloat::IEEEquad(), true);
192192 EXPECT_EQ(test.next(true), APFloat::opOK);
193193 EXPECT_TRUE(test.bitwiseIsEqual(expected));
194194
195195 // nextUp(-0) = +getSmallest()
196 test = APFloat::getZero(APFloat::IEEEquad, true);
197 expected = APFloat::getSmallest(APFloat::IEEEquad, false);
196 test = APFloat::getZero(APFloat::IEEEquad(), true);
197 expected = APFloat::getSmallest(APFloat::IEEEquad(), false);
198198 EXPECT_EQ(test.next(false), APFloat::opOK);
199199 EXPECT_TRUE(test.bitwiseIsEqual(expected));
200200
201201 // nextDown(-0) = -nextUp(0) = -getSmallest()
202 test = APFloat::getZero(APFloat::IEEEquad, true);
203 expected = APFloat::getSmallest(APFloat::IEEEquad, true);
202 test = APFloat::getZero(APFloat::IEEEquad(), true);
203 expected = APFloat::getSmallest(APFloat::IEEEquad(), true);
204204 EXPECT_EQ(test.next(true), APFloat::opOK);
205205 EXPECT_TRUE(test.bitwiseIsEqual(expected));
206206
213213 // * nextDown(+Smallest Normal) -> +Largest Denormal.
214214
215215 // nextUp(+Largest Denormal) -> +Smallest Normal.
216 test = APFloat(APFloat::IEEEquad, "0x0.ffffffffffffffffffffffffffffp-16382");
217 expected = APFloat(APFloat::IEEEquad,
216 test = APFloat(APFloat::IEEEquad(), "0x0.ffffffffffffffffffffffffffffp-16382");
217 expected = APFloat(APFloat::IEEEquad(),
218218 "0x1.0000000000000000000000000000p-16382");
219219 EXPECT_EQ(test.next(false), APFloat::opOK);
220220 EXPECT_FALSE(test.isDenormal());
221221 EXPECT_TRUE(test.bitwiseIsEqual(expected));
222222
223223 // nextDown(-Largest Denormal) -> -Smallest Normal.
224 test = APFloat(APFloat::IEEEquad,
224 test = APFloat(APFloat::IEEEquad(),
225225 "-0x0.ffffffffffffffffffffffffffffp-16382");
226 expected = APFloat(APFloat::IEEEquad,
226 expected = APFloat(APFloat::IEEEquad(),
227227 "-0x1.0000000000000000000000000000p-16382");
228228 EXPECT_EQ(test.next(true), APFloat::opOK);
229229 EXPECT_FALSE(test.isDenormal());
230230 EXPECT_TRUE(test.bitwiseIsEqual(expected));
231231
232232 // nextUp(-Smallest Normal) -> -LargestDenormal.
233 test = APFloat(APFloat::IEEEquad,
233 test = APFloat(APFloat::IEEEquad(),
234234 "-0x1.0000000000000000000000000000p-16382");
235 expected = APFloat(APFloat::IEEEquad,
235 expected = APFloat(APFloat::IEEEquad(),
236236 "-0x0.ffffffffffffffffffffffffffffp-16382");
237237 EXPECT_EQ(test.next(false), APFloat::opOK);
238238 EXPECT_TRUE(test.isDenormal());
239239 EXPECT_TRUE(test.bitwiseIsEqual(expected));
240240
241241 // nextDown(+Smallest Normal) -> +Largest Denormal.
242 test = APFloat(APFloat::IEEEquad,
242 test = APFloat(APFloat::IEEEquad(),
243243 "+0x1.0000000000000000000000000000p-16382");
244 expected = APFloat(APFloat::IEEEquad,
244 expected = APFloat(APFloat::IEEEquad(),
245245 "+0x0.ffffffffffffffffffffffffffffp-16382");
246246 EXPECT_EQ(test.next(true), APFloat::opOK);
247247 EXPECT_TRUE(test.isDenormal());
254254 // * nextDown(-Normal Binade Boundary + 1) -> -Normal Binade Boundary.
255255
256256 // nextUp(-Normal Binade Boundary) -> -Normal Binade Boundary + 1.
257 test = APFloat(APFloat::IEEEquad, "-0x1p+1");
258 expected = APFloat(APFloat::IEEEquad,
257 test = APFloat(APFloat::IEEEquad(), "-0x1p+1");
258 expected = APFloat(APFloat::IEEEquad(),
259259 "-0x1.ffffffffffffffffffffffffffffp+0");
260260 EXPECT_EQ(test.next(false), APFloat::opOK);
261261 EXPECT_TRUE(test.bitwiseIsEqual(expected));
262262
263263 // nextDown(+Normal Binade Boundary) -> +Normal Binade Boundary - 1.
264 test = APFloat(APFloat::IEEEquad, "0x1p+1");
265 expected = APFloat(APFloat::IEEEquad, "0x1.ffffffffffffffffffffffffffffp+0");
264 test = APFloat(APFloat::IEEEquad(), "0x1p+1");
265 expected = APFloat(APFloat::IEEEquad(), "0x1.ffffffffffffffffffffffffffffp+0");
266266 EXPECT_EQ(test.next(true), APFloat::opOK);
267267 EXPECT_TRUE(test.bitwiseIsEqual(expected));
268268
269269 // nextUp(+Normal Binade Boundary - 1) -> +Normal Binade Boundary.
270 test = APFloat(APFloat::IEEEquad, "0x1.ffffffffffffffffffffffffffffp+0");
271 expected = APFloat(APFloat::IEEEquad, "0x1p+1");
270 test = APFloat(APFloat::IEEEquad(), "0x1.ffffffffffffffffffffffffffffp+0");
271 expected = APFloat(APFloat::IEEEquad(), "0x1p+1");
272272 EXPECT_EQ(test.next(false), APFloat::opOK);
273273 EXPECT_TRUE(test.bitwiseIsEqual(expected));
274274
275275 // nextDown(-Normal Binade Boundary + 1) -> -Normal Binade Boundary.
276 test = APFloat(APFloat::IEEEquad, "-0x1.ffffffffffffffffffffffffffffp+0");
277 expected = APFloat(APFloat::IEEEquad, "-0x1p+1");
276 test = APFloat(APFloat::IEEEquad(), "-0x1.ffffffffffffffffffffffffffffp+0");
277 expected = APFloat(APFloat::IEEEquad(), "-0x1p+1");
278278 EXPECT_EQ(test.next(true), APFloat::opOK);
279279 EXPECT_TRUE(test.bitwiseIsEqual(expected));
280280
290290 // * nextDown(-Smallest Normal) -> -Smallest Normal - inc.
291291
292292 // nextUp(-Largest Denormal) -> -Largest Denormal + inc.
293 test = APFloat(APFloat::IEEEquad, "-0x0.ffffffffffffffffffffffffffffp-16382");
294 expected = APFloat(APFloat::IEEEquad,
293 test = APFloat(APFloat::IEEEquad(), "-0x0.ffffffffffffffffffffffffffffp-16382");
294 expected = APFloat(APFloat::IEEEquad(),
295295 "-0x0.fffffffffffffffffffffffffffep-16382");
296296 EXPECT_EQ(test.next(false), APFloat::opOK);
297297 EXPECT_TRUE(test.isDenormal());
299299 EXPECT_TRUE(test.bitwiseIsEqual(expected));
300300
301301 // nextDown(+Largest Denormal) -> +Largest Denormal - inc.
302 test = APFloat(APFloat::IEEEquad, "0x0.ffffffffffffffffffffffffffffp-16382");
303 expected = APFloat(APFloat::IEEEquad,
302 test = APFloat(APFloat::IEEEquad(), "0x0.ffffffffffffffffffffffffffffp-16382");
303 expected = APFloat(APFloat::IEEEquad(),
304304 "0x0.fffffffffffffffffffffffffffep-16382");
305305 EXPECT_EQ(test.next(true), APFloat::opOK);
306306 EXPECT_TRUE(test.isDenormal());
308308 EXPECT_TRUE(test.bitwiseIsEqual(expected));
309309
310310 // nextUp(+Smallest Normal) -> +Smallest Normal + inc.
311 test = APFloat(APFloat::IEEEquad, "0x1.0000000000000000000000000000p-16382");
312 expected = APFloat(APFloat::IEEEquad,
311 test = APFloat(APFloat::IEEEquad(), "0x1.0000000000000000000000000000p-16382");
312 expected = APFloat(APFloat::IEEEquad(),
313313 "0x1.0000000000000000000000000001p-16382");
314314 EXPECT_EQ(test.next(false), APFloat::opOK);
315315 EXPECT_TRUE(!test.isDenormal());
317317 EXPECT_TRUE(test.bitwiseIsEqual(expected));
318318
319319 // nextDown(-Smallest Normal) -> -Smallest Normal - inc.
320 test = APFloat(APFloat::IEEEquad, "-0x1.0000000000000000000000000000p-16382");
321 expected = APFloat(APFloat::IEEEquad,
320 test = APFloat(APFloat::IEEEquad(), "-0x1.0000000000000000000000000000p-16382");
321 expected = APFloat(APFloat::IEEEquad(),
322322 "-0x1.0000000000000000000000000001p-16382");
323323 EXPECT_EQ(test.next(true), APFloat::opOK);
324324 EXPECT_TRUE(!test.isDenormal());
335335 // * nextDown(0x1p-16382) -> 0x1.ffffffffffffffffffffffffffffp-16382
336336
337337 // nextUp(-0x1p-16381) -> -0x1.ffffffffffffffffffffffffffffp-16382
338 test = APFloat(APFloat::IEEEquad, "-0x1p-16381");
339 expected = APFloat(APFloat::IEEEquad,
338 test = APFloat(APFloat::IEEEquad(), "-0x1p-16381");
339 expected = APFloat(APFloat::IEEEquad(),
340340 "-0x1.ffffffffffffffffffffffffffffp-16382");
341341 EXPECT_EQ(test.next(false), APFloat::opOK);
342342 EXPECT_TRUE(test.bitwiseIsEqual(expected));
343343
344344 // nextDown(-0x1.ffffffffffffffffffffffffffffp-16382) ->
345345 // -0x1p-16381
346 test = APFloat(APFloat::IEEEquad, "-0x1.ffffffffffffffffffffffffffffp-16382");
347 expected = APFloat(APFloat::IEEEquad, "-0x1p-16381");
346 test = APFloat(APFloat::IEEEquad(), "-0x1.ffffffffffffffffffffffffffffp-16382");
347 expected = APFloat(APFloat::IEEEquad(), "-0x1p-16381");
348348 EXPECT_EQ(test.next(true), APFloat::opOK);
349349 EXPECT_TRUE(test.bitwiseIsEqual(expected));
350350
351351 // nextUp(0x1.ffffffffffffffffffffffffffffp-16382) -> 0x1p-16381
352 test = APFloat(APFloat::IEEEquad, "0x1.ffffffffffffffffffffffffffffp-16382");
353 expected = APFloat(APFloat::IEEEquad, "0x1p-16381");
352 test = APFloat(APFloat::IEEEquad(), "0x1.ffffffffffffffffffffffffffffp-16382");
353 expected = APFloat(APFloat::IEEEquad(), "0x1p-16381");
354354 EXPECT_EQ(test.next(false), APFloat::opOK);
355355 EXPECT_TRUE(test.bitwiseIsEqual(expected));
356356
357357 // nextDown(0x1p-16381) -> 0x1.ffffffffffffffffffffffffffffp-16382
358 test = APFloat(APFloat::IEEEquad, "0x1p-16381");
359 expected = APFloat(APFloat::IEEEquad,
358 test = APFloat(APFloat::IEEEquad(), "0x1p-16381");
359 expected = APFloat(APFloat::IEEEquad(),
360360 "0x1.ffffffffffffffffffffffffffffp-16382");
361361 EXPECT_EQ(test.next(true), APFloat::opOK);
362362 EXPECT_TRUE(test.bitwiseIsEqual(expected));
373373 // * nextDown(-Normal) -> -Normal.
374374
375375 // nextUp(+Denormal) -> +Denormal.
376 test = APFloat(APFloat::IEEEquad,
376 test = APFloat(APFloat::IEEEquad(),
377377 "0x0.ffffffffffffffffffffffff000cp-16382");
378 expected = APFloat(APFloat::IEEEquad,
378 expected = APFloat(APFloat::IEEEquad(),
379379 "0x0.ffffffffffffffffffffffff000dp-16382");
380380 EXPECT_EQ(test.next(false), APFloat::opOK);
381381 EXPECT_TRUE(test.isDenormal());
383383 EXPECT_TRUE(test.bitwiseIsEqual(expected));
384384
385385 // nextDown(+Denormal) -> +Denormal.
386 test = APFloat(APFloat::IEEEquad,
386 test = APFloat(APFloat::IEEEquad(),
387387 "0x0.ffffffffffffffffffffffff000cp-16382");
388 expected = APFloat(APFloat::IEEEquad,
388 expected = APFloat(APFloat::IEEEquad(),
389389 "0x0.ffffffffffffffffffffffff000bp-16382");
390390 EXPECT_EQ(test.next(true), APFloat::opOK);
391391 EXPECT_TRUE(test.isDenormal());
393393 EXPECT_TRUE(test.bitwiseIsEqual(expected));
394394
395395 // nextUp(-Denormal) -> -Denormal.
396 test = APFloat(APFloat::IEEEquad,
396 test = APFloat(APFloat::IEEEquad(),
397397 "-0x0.ffffffffffffffffffffffff000cp-16382");
398 expected = APFloat(APFloat::IEEEquad,
398 expected = APFloat(APFloat::IEEEquad(),
399399 "-0x0.ffffffffffffffffffffffff000bp-16382");
400400 EXPECT_EQ(test.next(false), APFloat::opOK);
401401 EXPECT_TRUE(test.isDenormal());
403403 EXPECT_TRUE(test.bitwiseIsEqual(expected));
404404
405405 // nextDown(-Denormal) -> -Denormal
406 test = APFloat(APFloat::IEEEquad,
406 test = APFloat(APFloat::IEEEquad(),
407407 "-0x0.ffffffffffffffffffffffff000cp-16382");
408 expected = APFloat(APFloat::IEEEquad,
408 expected = APFloat(APFloat::IEEEquad(),
409409 "-0x0.ffffffffffffffffffffffff000dp-16382");
410410 EXPECT_EQ(test.next(true), APFloat::opOK);
411411 EXPECT_TRUE(test.isDenormal());
413413 EXPECT_TRUE(test.bitwiseIsEqual(expected));
414414
415415 // nextUp(+Normal) -> +Normal.
416 test = APFloat(APFloat::IEEEquad,
416 test = APFloat(APFloat::IEEEquad(),
417417 "0x1.ffffffffffffffffffffffff000cp-16000");
418 expected = APFloat(APFloat::IEEEquad,
418 expected = APFloat(APFloat::IEEEquad(),
419419 "0x1.ffffffffffffffffffffffff000dp-16000");
420420 EXPECT_EQ(test.next(false), APFloat::opOK);
421421 EXPECT_TRUE(!test.isDenormal());
423423 EXPECT_TRUE(test.bitwiseIsEqual(expected));
424424
425425 // nextDown(+Normal) -> +Normal.
426 test = APFloat(APFloat::IEEEquad,
426 test = APFloat(APFloat::IEEEquad(),
427427 "0x1.ffffffffffffffffffffffff000cp-16000");
428 expected = APFloat(APFloat::IEEEquad,
428 expected = APFloat(APFloat::IEEEquad(),
429429 "0x1.ffffffffffffffffffffffff000bp-16000");
430430 EXPECT_EQ(test.next(true), APFloat::opOK);
431431 EXPECT_TRUE(!test.isDenormal());
433433 EXPECT_TRUE(test.bitwiseIsEqual(expected));
434434
435435 // nextUp(-Normal) -> -Normal.
436 test = APFloat(APFloat::IEEEquad,
436 test = APFloat(APFloat::IEEEquad(),
437437 "-0x1.ffffffffffffffffffffffff000cp-16000");
438 expected = APFloat(APFloat::IEEEquad,
438 expected = APFloat(APFloat::IEEEquad(),
439439 "-0x1.ffffffffffffffffffffffff000bp-16000");
440440 EXPECT_EQ(test.next(false), APFloat::opOK);
441441 EXPECT_TRUE(!test.isDenormal());
443443 EXPECT_TRUE(test.bitwiseIsEqual(expected));
444444
445445 // nextDown(-Normal) -> -Normal.
446 test = APFloat(APFloat::IEEEquad,
446 test = APFloat(APFloat::IEEEquad(),
447447 "-0x1.ffffffffffffffffffffffff000cp-16000");
448 expected = APFloat(APFloat::IEEEquad,
448 expected = APFloat(APFloat::IEEEquad(),
449449 "-0x1.ffffffffffffffffffffffff000dp-16000");
450450 EXPECT_EQ(test.next(true), APFloat::opOK);
451451 EXPECT_TRUE(!test.isDenormal());
508508
509509 // Test -ve sign preservation when small negative results underflow.
510510 {
511 APFloat f1(APFloat::IEEEdouble, "-0x1p-1074");
512 APFloat f2(APFloat::IEEEdouble, "+0x1p-1074");
511 APFloat f1(APFloat::IEEEdouble(), "-0x1p-1074");
512 APFloat f2(APFloat::IEEEdouble(), "+0x1p-1074");
513513 APFloat f3(0.0);
514514 f1.fusedMultiplyAdd(f2, f3, APFloat::rmNearestTiesToEven);
515515 EXPECT_TRUE(f1.isNegative() && f1.isZero());
517517
518518 // Test x87 extended precision case from http://llvm.org/PR20728.
519519 {
520 APFloat M1(APFloat::x87DoubleExtended, 1.0);
521 APFloat M2(APFloat::x87DoubleExtended, 1.0);
522 APFloat A(APFloat::x87DoubleExtended, 3.0);
520 APFloat M1(APFloat::x87DoubleExtended(), 1.0);
521 APFloat M2(APFloat::x87DoubleExtended(), 1.0);
522 APFloat A(APFloat::x87DoubleExtended(), 3.0);
523523
524524 bool losesInfo = false;
525525 M1.fusedMultiplyAdd(M1, A, APFloat::rmNearestTiesToEven);
526 M1.convert(APFloat::IEEEsingle, APFloat::rmNearestTiesToEven, &losesInfo);
526 M1.convert(APFloat::IEEEsingle(), APFloat::rmNearestTiesToEven, &losesInfo);
527527 EXPECT_FALSE(losesInfo);
528528 EXPECT_EQ(4.0f, M1.convertToFloat());
529529 }
532532 TEST(APFloatTest, MinNum) {
533533 APFloat f1(1.0);
534534 APFloat f2(2.0);
535 APFloat nan = APFloat::getNaN(APFloat::IEEEdouble);
535 APFloat nan = APFloat::getNaN(APFloat::IEEEdouble());
536536
537537 EXPECT_EQ(1.0, minnum(f1, f2).convertToDouble());
538538 EXPECT_EQ(1.0, minnum(f2, f1).convertToDouble());
543543 TEST(APFloatTest, MaxNum) {
544544 APFloat f1(1.0);
545545 APFloat f2(2.0);
546 APFloat nan = APFloat::getNaN(APFloat::IEEEdouble);
546 APFloat nan = APFloat::getNaN(APFloat::IEEEdouble());
547547
548548 EXPECT_EQ(2.0, maxnum(f1, f2).convertToDouble());
549549 EXPECT_EQ(2.0, maxnum(f2, f1).convertToDouble());
557557 // Test single precision
558558 {
559559 const char *MinNormalStr = "1.17549435082228750797e-38";
560 EXPECT_FALSE(APFloat(APFloat::IEEEsingle, MinNormalStr).isDenormal());
561 EXPECT_FALSE(APFloat(APFloat::IEEEsingle, 0.0).isDenormal());
562
563 APFloat Val2(APFloat::IEEEsingle, 2.0e0);
564 APFloat T(APFloat::IEEEsingle, MinNormalStr);
560 EXPECT_FALSE(APFloat(APFloat::IEEEsingle(), MinNormalStr).isDenormal());
561 EXPECT_FALSE(APFloat(APFloat::IEEEsingle(), 0.0).isDenormal());
562
563 APFloat Val2(APFloat::IEEEsingle(), 2.0e0);
564 APFloat T(APFloat::IEEEsingle(), MinNormalStr);
565565 T.divide(Val2, rdmd);
566566 EXPECT_TRUE(T.isDenormal());
567567 }
569569 // Test double precision
570570 {
571571 const char *MinNormalStr = "2.22507385850720138309e-308";
572 EXPECT_FALSE(APFloat(APFloat::IEEEdouble, MinNormalStr).isDenormal());
573 EXPECT_FALSE(APFloat(APFloat::IEEEdouble, 0.0).isDenormal());
574
575 APFloat Val2(APFloat::IEEEdouble, 2.0e0);
576 APFloat T(APFloat::IEEEdouble, MinNormalStr);
572 EXPECT_FALSE(APFloat(APFloat::IEEEdouble(), MinNormalStr).isDenormal());
573 EXPECT_FALSE(APFloat(APFloat::IEEEdouble(), 0.0).isDenormal());
574
575 APFloat Val2(APFloat::IEEEdouble(), 2.0e0);
576 APFloat T(APFloat::IEEEdouble(), MinNormalStr);
577577 T.divide(Val2, rdmd);
578578 EXPECT_TRUE(T.isDenormal());
579579 }
581581 // Test Intel double-ext
582582 {
583583 const char *MinNormalStr = "3.36210314311209350626e-4932";
584 EXPECT_FALSE(APFloat(APFloat::x87DoubleExtended, MinNormalStr).isDenormal());
585 EXPECT_FALSE(APFloat(APFloat::x87DoubleExtended, 0.0).isDenormal());
586
587 APFloat Val2(APFloat::x87DoubleExtended, 2.0e0);
588 APFloat T(APFloat::x87DoubleExtended, MinNormalStr);
584 EXPECT_FALSE(APFloat(APFloat::x87DoubleExtended(), MinNormalStr).isDenormal());
585 EXPECT_FALSE(APFloat(APFloat::x87DoubleExtended(), 0.0).isDenormal());
586
587 APFloat Val2(APFloat::x87DoubleExtended(), 2.0e0);
588 APFloat T(APFloat::x87DoubleExtended(), MinNormalStr);
589589 T.divide(Val2, rdmd);
590590 EXPECT_TRUE(T.isDenormal());
591591 }
593593 // Test quadruple precision
594594 {
595595 const char *MinNormalStr = "3.36210314311209350626267781732175260e-4932";
596 EXPECT_FALSE(APFloat(APFloat::IEEEquad, MinNormalStr).isDenormal());
597 EXPECT_FALSE(APFloat(APFloat::IEEEquad, 0.0).isDenormal());
598
599 APFloat Val2(APFloat::IEEEquad, 2.0e0);
600 APFloat T(APFloat::IEEEquad, MinNormalStr);
596 EXPECT_FALSE(APFloat(APFloat::IEEEquad(), MinNormalStr).isDenormal());
597 EXPECT_FALSE(APFloat(APFloat::IEEEquad(), 0.0).isDenormal());
598
599 APFloat Val2(APFloat::IEEEquad(), 2.0e0);
600 APFloat T(APFloat::IEEEquad(), MinNormalStr);
601601 T.divide(Val2, rdmd);
602602 EXPECT_TRUE(T.isDenormal());
603603 }
616616 TEST(APFloatTest, DecimalStringsWithoutNullTerminators) {
617617 // Make sure that we can parse strings without null terminators.
618618 // rdar://14323230.
619 APFloat Val(APFloat::IEEEdouble);
619 APFloat Val(APFloat::IEEEdouble());
620620 Val.convertFromString(StringRef("0.00", 3),
621621 llvm::APFloat::rmNearestTiesToEven);
622622 EXPECT_EQ(Val.convertToDouble(), 0.0);
639639 }
640640
641641 TEST(APFloatTest, fromZeroDecimalString) {
642 EXPECT_EQ( 0.0, APFloat(APFloat::IEEEdouble, "0").convertToDouble());
643 EXPECT_EQ(+0.0, APFloat(APFloat::IEEEdouble, "+0").convertToDouble());
644 EXPECT_EQ(-0.0, APFloat(APFloat::IEEEdouble, "-0").convertToDouble());
645
646 EXPECT_EQ( 0.0, APFloat(APFloat::IEEEdouble, "0.").convertToDouble());
647 EXPECT_EQ(+0.0, APFloat(APFloat::IEEEdouble, "+0.").convertToDouble());
648 EXPECT_EQ(-0.0, APFloat(APFloat::IEEEdouble, "-0.").convertToDouble());
649
650 EXPECT_EQ( 0.0, APFloat(APFloat::IEEEdouble, ".0").convertToDouble());
651 EXPECT_EQ(+0.0, APFloat(APFloat::IEEEdouble, "+.0").convertToDouble());
652 EXPECT_EQ(-0.0, APFloat(APFloat::IEEEdouble, "-.0").convertToDouble());
653
654 EXPECT_EQ( 0.0, APFloat(APFloat::IEEEdouble, "0.0").convertToDouble());
655 EXPECT_EQ(+0.0, APFloat(APFloat::IEEEdouble, "+0.0").convertToDouble());
656 EXPECT_EQ(-0.0, APFloat(APFloat::IEEEdouble, "-0.0").convertToDouble());
657
658 EXPECT_EQ( 0.0, APFloat(APFloat::IEEEdouble, "00000.").convertToDouble());
659 EXPECT_EQ(+0.0, APFloat(APFloat::IEEEdouble, "+00000.").convertToDouble());
660 EXPECT_EQ(-0.0, APFloat(APFloat::IEEEdouble, "-00000.").convertToDouble());
661
662 EXPECT_EQ(0.0, APFloat(APFloat::IEEEdouble, ".00000").convertToDouble());
663 EXPECT_EQ(+0.0, APFloat(APFloat::IEEEdouble, "+.00000").convertToDouble());
664 EXPECT_EQ(-0.0, APFloat(APFloat::IEEEdouble, "-.00000").convertToDouble());
665
666 EXPECT_EQ( 0.0, APFloat(APFloat::IEEEdouble, "0000.00000").convertToDouble());
667 EXPECT_EQ(+0.0, APFloat(APFloat::IEEEdouble, "+0000.00000").convertToDouble());
668 EXPECT_EQ(-0.0, APFloat(APFloat::IEEEdouble, "-0000.00000").convertToDouble());
642 EXPECT_EQ( 0.0, APFloat(APFloat::IEEEdouble(), "0").convertToDouble());
643 EXPECT_EQ(+0.0, APFloat(APFloat::IEEEdouble(), "+0").convertToDouble());
644 EXPECT_EQ(-0.0, APFloat(APFloat::IEEEdouble(), "-0").convertToDouble());
645
646 EXPECT_EQ( 0.0, APFloat(APFloat::IEEEdouble(), "0.").convertToDouble());
647 EXPECT_EQ(+0.0, APFloat(APFloat::IEEEdouble(), "+0.").convertToDouble());
648 EXPECT_EQ(-0.0, APFloat(APFloat::IEEEdouble(), "-0.").convertToDouble());
649
650 EXPECT_EQ( 0.0, APFloat(APFloat::IEEEdouble(), ".0").convertToDouble());
651 EXPECT_EQ(+0.0, APFloat(APFloat::IEEEdouble(), "+.0").convertToDouble());
652 EXPECT_EQ(-0.0, APFloat(APFloat::IEEEdouble(), "-.0").convertToDouble());
653
654 EXPECT_EQ( 0.0, APFloat(APFloat::IEEEdouble(), "0.0").convertToDouble());
655 EXPECT_EQ(+0.0, APFloat(APFloat::IEEEdouble(), "+0.0").convertToDouble());
656 EXPECT_EQ(-0.0, APFloat(APFloat::IEEEdouble(), "-0.0").convertToDouble());
657
658 EXPECT_EQ( 0.0, APFloat(APFloat::IEEEdouble(), "00000.").convertToDouble());
659 EXPECT_EQ(+0.0, APFloat(APFloat::IEEEdouble(), "+00000.").convertToDouble());
660 EXPECT_EQ(-0.0, APFloat(APFloat::IEEEdouble(), "-00000.").convertToDouble());
661
662 EXPECT_EQ(0.0, APFloat(APFloat::IEEEdouble(), ".00000").convertToDouble());
663 EXPECT_EQ(+0.0, APFloat(APFloat::IEEEdouble(), "+.00000").convertToDouble());
664 EXPECT_EQ(-0.0, APFloat(APFloat::IEEEdouble(), "-.00000").convertToDouble());
665
666 EXPECT_EQ( 0.0, APFloat(APFloat::IEEEdouble(), "0000.00000").convertToDouble());
667 EXPECT_EQ(+0.0, APFloat(APFloat::IEEEdouble(), "+0000.00000").convertToDouble());
668 EXPECT_EQ(-0.0, APFloat(APFloat::IEEEdouble(), "-0000.00000").convertToDouble());
669669 }
670670
671671 TEST(APFloatTest, fromZeroDecimalSingleExponentString) {
672 EXPECT_EQ( 0.0, APFloat(APFloat::IEEEdouble, "0e1").convertToDouble());
673 EXPECT_EQ(+0.0, APFloat(APFloat::IEEEdouble, "+0e1").convertToDouble());
674 EXPECT_EQ(-0.0, APFloat(APFloat::IEEEdouble, "-0e1").convertToDouble());
675
676 EXPECT_EQ( 0.0, APFloat(APFloat::IEEEdouble, "0e+1").convertToDouble());
677 EXPECT_EQ(+0.0, APFloat(APFloat::IEEEdouble, "+0e+1").convertToDouble());
678 EXPECT_EQ(-0.0, APFloat(APFloat::IEEEdouble, "-0e+1").convertToDouble());
679
680 EXPECT_EQ( 0.0, APFloat(APFloat::IEEEdouble, "0e-1").convertToDouble());
681 EXPECT_EQ(+0.0, APFloat(APFloat::IEEEdouble, "+0e-1").convertToDouble());
682 EXPECT_EQ(-0.0, APFloat(APFloat::IEEEdouble, "-0e-1").convertToDouble());
683
684
685 EXPECT_EQ( 0.0, APFloat(APFloat::IEEEdouble, "0.e1").convertToDouble());
686 EXPECT_EQ(+0.0, APFloat(APFloat::IEEEdouble, "+0.e1").convertToDouble());
687 EXPECT_EQ(-0.0, APFloat(APFloat::IEEEdouble, "-0.e1").convertToDouble());
688
689 EXPECT_EQ( 0.0, APFloat(APFloat::IEEEdouble, "0.e+1").convertToDouble());
690 EXPECT_EQ(+0.0, APFloat(APFloat::IEEEdouble, "+0.e+1").convertToDouble());
691 EXPECT_EQ(-0.0, APFloat(APFloat::IEEEdouble, "-0.e+1").convertToDouble());
692
693 EXPECT_EQ( 0.0, APFloat(APFloat::IEEEdouble, "0.e-1").convertToDouble());
694 EXPECT_EQ(+0.0, APFloat(APFloat::IEEEdouble, "+0.e-1").convertToDouble());
695 EXPECT_EQ(-0.0, APFloat(APFloat::IEEEdouble, "-0.e-1").convertToDouble());
696
697 EXPECT_EQ( 0.0, APFloat(APFloat::IEEEdouble, ".0e1").convertToDouble());
698 EXPECT_EQ(+0.0, APFloat(APFloat::IEEEdouble, "+.0e1").convertToDouble());
699 EXPECT_EQ(-0.0, APFloat(APFloat::IEEEdouble, "-.0e1").convertToDouble());
700
701 EXPECT_EQ( 0.0, APFloat(APFloat::IEEEdouble, ".0e+1").convertToDouble());
702 EXPECT_EQ(+0.0, APFloat(APFloat::IEEEdouble, "+.0e+1").convertToDouble());
703 EXPECT_EQ(-0.0, APFloat(APFloat::IEEEdouble, "-.0e+1").convertToDouble());
704
705 EXPECT_EQ( 0.0, APFloat(APFloat::IEEEdouble, ".0e-1").convertToDouble());
706 EXPECT_EQ(+0.0, APFloat(APFloat::IEEEdouble, "+.0e-1").convertToDouble());
707 EXPECT_EQ(-0.0, APFloat(APFloat::IEEEdouble, "-.0e-1").convertToDouble());
708
709
710 EXPECT_EQ( 0.0, APFloat(APFloat::IEEEdouble, "0.0e1").convertToDouble());
711 EXPECT_EQ(+0.0, APFloat(APFloat::IEEEdouble, "+0.0e1").convertToDouble());
712 EXPECT_EQ(-0.0, APFloat(APFloat::IEEEdouble, "-0.0e1").convertToDouble());
713
714 EXPECT_EQ( 0.0, APFloat(APFloat::IEEEdouble, "0.0e+1").convertToDouble());
715 EXPECT_EQ(+0.0, APFloat(APFloat::IEEEdouble, "+0.0e+1").convertToDouble());
716 EXPECT_EQ(-0.0, APFloat(APFloat::IEEEdouble, "-0.0e+1").convertToDouble());
717
718 EXPECT_EQ( 0.0, APFloat(APFloat::IEEEdouble, "0.0e-1").convertToDouble());
719 EXPECT_EQ(+0.0, APFloat(APFloat::IEEEdouble, "+0.0e-1").convertToDouble());
720 EXPECT_EQ(-0.0, APFloat(APFloat::IEEEdouble, "-0.0e-1").convertToDouble());
721
722
723 EXPECT_EQ( 0.0, APFloat(APFloat::IEEEdouble, "000.0000e1").convertToDouble());
724 EXPECT_EQ(+0.0, APFloat(APFloat::IEEEdouble, "+000.0000e+1").convertToDouble());
725 EXPECT_EQ(-0.0, APFloat(APFloat::IEEEdouble, "-000.0000e+1").convertToDouble());
672 EXPECT_EQ( 0.0, APFloat(APFloat::IEEEdouble(), "0e1").convertToDouble());
673 EXPECT_EQ(+0.0, APFloat(APFloat::IEEEdouble(), "+0e1").convertToDouble());
674 EXPECT_EQ(-0.0, APFloat(APFloat::IEEEdouble(), "-0e1").convertToDouble());
675
676 EXPECT_EQ( 0.0, APFloat(APFloat::IEEEdouble(), "0e+1").convertToDouble());
677 EXPECT_EQ(+0.0, APFloat(APFloat::IEEEdouble(), "+0e+1").convertToDouble());
678 EXPECT_EQ(-0.0, APFloat(APFloat::IEEEdouble(), "-0e+1").convertToDouble());
679
680 EXPECT_EQ( 0.0, APFloat(APFloat::IEEEdouble(), "0e-1").convertToDouble());
681 EXPECT_EQ(+0.0, APFloat(APFloat::IEEEdouble(), "+0e-1").convertToDouble());
682 EXPECT_EQ(-0.0, APFloat(APFloat::IEEEdouble(), "-0e-1").convertToDouble());
683
684
685 EXPECT_EQ( 0.0, APFloat(APFloat::IEEEdouble(), "0.e1").convertToDouble());
686 EXPECT_EQ(+0.0, APFloat(APFloat::IEEEdouble(), "+0.e1").convertToDouble());
687 EXPECT_EQ(-0.0, APFloat(APFloat::IEEEdouble(), "-0.e1").convertToDouble());
688
689 EXPECT_EQ( 0.0, APFloat(APFloat::IEEEdouble(), "0.e+1").convertToDouble());
690 EXPECT_EQ(+0.0, APFloat(APFloat::IEEEdouble(), "+0.e+1").convertToDouble());
691 EXPECT_EQ(-0.0, APFloat(APFloat::IEEEdouble(), "-0.e+1").convertToDouble());
692
693 EXPECT_EQ( 0.0, APFloat(APFloat::IEEEdouble(), "0.e-1").convertToDouble());
694 EXPECT_EQ(+0.0, APFloat(APFloat::IEEEdouble(), "+0.e-1").convertToDouble());
695 EXPECT_EQ(-0.0, APFloat(APFloat::IEEEdouble(), "-0.e-1").convertToDouble());
696
697 EXPECT_EQ( 0.0, APFloat(APFloat::IEEEdouble(), ".0e1").convertToDouble());
698 EXPECT_EQ(+0.0, APFloat(APFloat::IEEEdouble(), "+.0e1").convertToDouble());
699 EXPECT_EQ(-0.0, APFloat(APFloat::IEEEdouble(), "-.0e1").convertToDouble());
700
701 EXPECT_EQ( 0.0, APFloat(APFloat::IEEEdouble(), ".0e+1").convertToDouble());
702 EXPECT_EQ(+0.0, APFloat(APFloat::IEEEdouble(), "+.0e+1").convertToDouble());
703 EXPECT_EQ(-0.0, APFloat(APFloat::IEEEdouble(), "-.0e+1").convertToDouble());
704
705 EXPECT_EQ( 0.0, APFloat(APFloat::IEEEdouble(), ".0e-1").convertToDouble());
706 EXPECT_EQ(+0.0, APFloat(APFloat::IEEEdouble(), "+.0e-1").convertToDouble());
707 EXPECT_EQ(-0.0, APFloat(APFloat::IEEEdouble(), "-.0e-1").convertToDouble());
708
709
710 EXPECT_EQ( 0.0, APFloat(APFloat::IEEEdouble(), "0.0e1").convertToDouble());
711 EXPECT_EQ(+0.0, APFloat(APFloat::IEEEdouble(), "+0.0e1").convertToDouble());
712 EXPECT_EQ(-0.0, APFloat(APFloat::IEEEdouble(), "-0.0e1").convertToDouble());
713
714 EXPECT_EQ( 0.0, APFloat(APFloat::IEEEdouble(), "0.0e+1").convertToDouble());
715 EXPECT_EQ(+0.0, APFloat(APFloat::IEEEdouble(), "+0.0e+1").convertToDouble());
716 EXPECT_EQ(-0.0, APFloat(APFloat::IEEEdouble(), "-0.0e+1").convertToDouble());
717
718 EXPECT_EQ( 0.0, APFloat(APFloat::IEEEdouble(), "0.0e-1").convertToDouble());
719 EXPECT_EQ(+0.0, APFloat(APFloat::IEEEdouble(), "+0.0e-1").convertToDouble());
720 EXPECT_EQ(-0.0, APFloat(APFloat::IEEEdouble(), "-0.0e-1").convertToDouble());
721
722
723 EXPECT_EQ( 0.0, APFloat(APFloat::IEEEdouble(), "000.0000e1").convertToDouble());
724 EXPECT_EQ(+0.0, APFloat(APFloat::IEEEdouble(), "+000.0000e+1").convertToDouble());
725 EXPECT_EQ(-0.0, APFloat(APFloat::IEEEdouble(), "-000.0000e+1").convertToDouble());
726726 }
727727
728728 TEST(APFloatTest, fromZeroDecimalLargeExponentString) {
729 EXPECT_EQ( 0.0, APFloat(APFloat::IEEEdouble, "0e1234").convertToDouble());
730 EXPECT_EQ(+0.0, APFloat(APFloat::IEEEdouble, "+0e1234").convertToDouble());
731 EXPECT_EQ(-0.0, APFloat(APFloat::IEEEdouble, "-0e1234").convertToDouble());
732
733 EXPECT_EQ( 0.0, APFloat(APFloat::IEEEdouble, "0e+1234").convertToDouble());
734 EXPECT_EQ(+0.0, APFloat(APFloat::IEEEdouble, "+0e+1234").convertToDouble());
735 EXPECT_EQ(-0.0, APFloat(APFloat::IEEEdouble, "-0e+1234").convertToDouble());
736
737 EXPECT_EQ( 0.0, APFloat(APFloat::IEEEdouble, "0e-1234").convertToDouble());
738 EXPECT_EQ(+0.0, APFloat(APFloat::IEEEdouble, "+0e-1234").convertToDouble());
739 EXPECT_EQ(-0.0, APFloat(APFloat::IEEEdouble, "-0e-1234").convertToDouble());
740
741 EXPECT_EQ(0.0, APFloat(APFloat::IEEEdouble, "000.0000e1234").convertToDouble());
742 EXPECT_EQ(0.0, APFloat(APFloat::IEEEdouble, "000.0000e-1234").convertToDouble());
743
744 EXPECT_EQ(0.0, APFloat(APFloat::IEEEdouble, StringRef("0e1234\02", 6)).convertToDouble());
729 EXPECT_EQ( 0.0, APFloat(APFloat::IEEEdouble(), "0e1234").convertToDouble());
730 EXPECT_EQ(+0.0, APFloat(APFloat::IEEEdouble(), "+0e1234").convertToDouble());
731 EXPECT_EQ(-0.0, APFloat(APFloat::IEEEdouble(), "-0e1234").convertToDouble());
732
733 EXPECT_EQ( 0.0, APFloat(APFloat::IEEEdouble(), "0e+1234").convertToDouble());
734 EXPECT_EQ(+0.0, APFloat(APFloat::IEEEdouble(), "+0e+1234").convertToDouble());
735 EXPECT_EQ(-0.0, APFloat(APFloat::IEEEdouble(), "-0e+1234").convertToDouble());
736
737 EXPECT_EQ( 0.0, APFloat(APFloat::IEEEdouble(), "0e-1234").convertToDouble());
738 EXPECT_EQ(+0.0, APFloat(APFloat::IEEEdouble(), "+0e-1234").convertToDouble());
739 EXPECT_EQ(-0.0, APFloat(APFloat::IEEEdouble(), "-0e-1234").convertToDouble());
740
741 EXPECT_EQ(0.0, APFloat(APFloat::IEEEdouble(), "000.0000e1234").convertToDouble());
742 EXPECT_EQ(0.0, APFloat(APFloat::IEEEdouble(), "000.0000e-1234").convertToDouble());
743
744 EXPECT_EQ(0.0, APFloat(APFloat::IEEEdouble(), StringRef("0e1234\02", 6)).convertToDouble());
745745 }
746746
747747 TEST(APFloatTest, fromZeroHexadecimalString) {
748 EXPECT_EQ( 0.0, APFloat(APFloat::IEEEdouble, "0x0p1").convertToDouble());
749 EXPECT_EQ(+0.0, APFloat(APFloat::IEEEdouble, "+0x0p1").convertToDouble());
750 EXPECT_EQ(-0.0, APFloat(APFloat::IEEEdouble, "-0x0p1").convertToDouble());
751
752 EXPECT_EQ( 0.0, APFloat(APFloat::IEEEdouble, "0x0p+1").convertToDouble());
753 EXPECT_EQ(+0.0, APFloat(APFloat::IEEEdouble, "+0x0p+1").convertToDouble());
754 EXPECT_EQ(-0.0, APFloat(APFloat::IEEEdouble, "-0x0p+1").convertToDouble());
755
756 EXPECT_EQ( 0.0, APFloat(APFloat::IEEEdouble, "0x0p-1").convertToDouble());
757 EXPECT_EQ(+0.0, APFloat(APFloat::IEEEdouble, "+0x0p-1").convertToDouble());
758 EXPECT_EQ(-0.0, APFloat(APFloat::IEEEdouble, "-0x0p-1").convertToDouble());
759
760
761 EXPECT_EQ( 0.0, APFloat(APFloat::IEEEdouble, "0x0.p1").convertToDouble());
762 EXPECT_EQ(+0.0, APFloat(APFloat::IEEEdouble, "+0x0.p1").convertToDouble());
763 EXPECT_EQ(-0.0, APFloat(APFloat::IEEEdouble, "-0x0.p1").convertToDouble());
764
765 EXPECT_EQ( 0.0, APFloat(APFloat::IEEEdouble, "0x0.p+1").convertToDouble());
766 EXPECT_EQ(+0.0, APFloat(APFloat::IEEEdouble, "+0x0.p+1").convertToDouble());
767 EXPECT_EQ(-0.0, APFloat(APFloat::IEEEdouble, "-0x0.p+1").convertToDouble());
768
769 EXPECT_EQ( 0.0, APFloat(APFloat::IEEEdouble, "0x0.p-1").convertToDouble());
770 EXPECT_EQ(+0.0, APFloat(APFloat::IEEEdouble, "+0x0.p-1").convertToDouble());
771 EXPECT_EQ(-0.0, APFloat(APFloat::IEEEdouble, "-0x0.p-1").convertToDouble());
772
773
774 EXPECT_EQ( 0.0, APFloat(APFloat::IEEEdouble, "0x.0p1").convertToDouble());
775 EXPECT_EQ(+0.0, APFloat(APFloat::IEEEdouble, "+0x.0p1").convertToDouble());
776 EXPECT_EQ(-0.0, APFloat(APFloat::IEEEdouble, "-0x.0p1").convertToDouble());
777
778 EXPECT_EQ( 0.0, APFloat(APFloat::IEEEdouble, "0x.0p+1").convertToDouble());
779 EXPECT_EQ(+0.0, APFloat(APFloat::IEEEdouble, "+0x.0p+1").convertToDouble());
780 EXPECT_EQ(-0.0, APFloat(APFloat::IEEEdouble, "-0x.0p+1").convertToDouble());
781
782 EXPECT_EQ( 0.0, APFloat(APFloat::IEEEdouble, "0x.0p-1").convertToDouble());
783 EXPECT_EQ(+0.0, APFloat(APFloat::IEEEdouble, "+0x.0p-1").convertToDouble());
784 EXPECT_EQ(-0.0, APFloat(APFloat::IEEEdouble, "-0x.0p-1").convertToDouble());
785
786
787 EXPECT_EQ( 0.0, APFloat(APFloat::IEEEdouble, "0x0.0p1").convertToDouble());
788 EXPECT_EQ(+0.0, APFloat(APFloat::IEEEdouble, "+0x0.0p1").convertToDouble());
789 EXPECT_EQ(-0.0, APFloat(APFloat::IEEEdouble, "-0x0.0p1").convertToDouble());
790
791 EXPECT_EQ( 0.0, APFloat(APFloat::IEEEdouble, "0x0.0p+1").convertToDouble());
792 EXPECT_EQ(+0.0, APFloat(APFloat::IEEEdouble, "+0x0.0p+1").convertToDouble());
793 EXPECT_EQ(-0.0, APFloat(APFloat::IEEEdouble, "-0x0.0p+1").convertToDouble());
794
795 EXPECT_EQ( 0.0, APFloat(APFloat::IEEEdouble, "0x0.0p-1").convertToDouble());
796 EXPECT_EQ(+0.0, APFloat(APFloat::IEEEdouble, "+0x0.0p-1").convertToDouble());
797 EXPECT_EQ(-0.0, APFloat(APFloat::IEEEdouble, "-0x0.0p-1").convertToDouble());
798
799
800 EXPECT_EQ( 0.0, APFloat(APFloat::IEEEdouble, "0x00000.p1").convertToDouble());
801 EXPECT_EQ( 0.0, APFloat(APFloat::IEEEdouble, "0x0000.00000p1").convertToDouble());
802 EXPECT_EQ( 0.0, APFloat(APFloat::IEEEdouble, "0x.00000p1").convertToDouble());
803 EXPECT_EQ( 0.0, APFloat(APFloat::IEEEdouble, "0x0.p1").convertToDouble());
804 EXPECT_EQ( 0.0, APFloat(APFloat::IEEEdouble, "0x0p1234").convertToDouble());
805 EXPECT_EQ(-0.0, APFloat(APFloat::IEEEdouble, "-0x0p1234").convertToDouble());
806 EXPECT_EQ( 0.0, APFloat(APFloat::IEEEdouble, "0x00000.p1234").convertToDouble());
807 EXPECT_EQ( 0.0, APFloat(APFloat::IEEEdouble, "0x0000.00000p1234").convertToDouble());
808 EXPECT_EQ( 0.0, APFloat(APFloat::IEEEdouble, "0x.00000p1234").convertToDouble());
809 EXPECT_EQ( 0.0, APFloat(APFloat::IEEEdouble, "0x0.p1234").convertToDouble());
748 EXPECT_EQ( 0.0, APFloat(APFloat::IEEEdouble(), "0x0p1").convertToDouble());
749 EXPECT_EQ(+0.0, APFloat(APFloat::IEEEdouble(), "+0x0p1").convertToDouble());
750 EXPECT_EQ(-0.0, APFloat(APFloat::IEEEdouble(), "-0x0p1").convertToDouble());
751
752 EXPECT_EQ( 0.0, APFloat(APFloat::IEEEdouble(), "0x0p+1").convertToDouble());
753 EXPECT_EQ(+0.0, APFloat(APFloat::IEEEdouble(), "+0x0p+1").convertToDouble());
754 EXPECT_EQ(-0.0, APFloat(APFloat::IEEEdouble(), "-0x0p+1").convertToDouble());
755
756 EXPECT_EQ( 0.0, APFloat(APFloat::IEEEdouble(), "0x0p-1").convertToDouble());
757 EXPECT_EQ(+0.0, APFloat(APFloat::IEEEdouble(), "+0x0p-1").convertToDouble());
758 EXPECT_EQ(-0.0, APFloat(APFloat::IEEEdouble(), "-0x0p-1").convertToDouble());
759
760
761 EXPECT_EQ( 0.0, APFloat(APFloat::IEEEdouble(), "0x0.p1").convertToDouble());
762 EXPECT_EQ(+0.0, APFloat(APFloat::IEEEdouble(), "+0x0.p1").convertToDouble());
763 EXPECT_EQ(-0.0, APFloat(APFloat::IEEEdouble(), "-0x0.p1").convertToDouble());
764
765 EXPECT_EQ( 0.0, APFloat(APFloat::IEEEdouble(), "0x0.p+1").convertToDouble());
766 EXPECT_EQ(+0.0, APFloat(APFloat::IEEEdouble(), "+0x0.p+1").convertToDouble());
767 EXPECT_EQ(-0.0, APFloat(APFloat::IEEEdouble(), "-0x0.p+1").convertToDouble());
768
769 EXPECT_EQ( 0.0, APFloat(APFloat::IEEEdouble(), "0x0.p-1").convertToDouble());
770 EXPECT_EQ(+0.0, APFloat(APFloat::IEEEdouble(), "+0x0.p-1").convertToDouble());
771 EXPECT_EQ(-0.0, APFloat(APFloat::IEEEdouble(), "-0x0.p-1").convertToDouble());
772
773
774 EXPECT_EQ( 0.0, APFloat(APFloat::IEEEdouble(), "0x.0p1").convertToDouble());
775 EXPECT_EQ(+0.0, APFloat(APFloat::IEEEdouble(), "+0x.0p1").convertToDouble());
776 EXPECT_EQ(-0.0, APFloat(APFloat::IEEEdouble(), "-0x.0p1").convertToDouble());
777
778 EXPECT_EQ( 0.0, APFloat(APFloat::IEEEdouble(), "0x.0p+1").convertToDouble());
779 EXPECT_EQ(+0.0, APFloat(APFloat::IEEEdouble(), "+0x.0p+1").convertToDouble());
780 EXPECT_EQ(-0.0, APFloat(APFloat::IEEEdouble(), "-0x.0p+1").convertToDouble());
781
782 EXPECT_EQ( 0.0, APFloat(APFloat::IEEEdouble(), "0x.0p-1").convertToDouble());
783 EXPECT_EQ(+0.0, APFloat(APFloat::IEEEdouble(), "+0x.0p-1").convertToDouble());
784 EXPECT_EQ(-0.0, APFloat(APFloat::IEEEdouble(), "-0x.0p-1").convertToDouble());
785
786
787 EXPECT_EQ( 0.0, APFloat(APFloat::IEEEdouble(), "0x0.0p1").convertToDouble());
788 EXPECT_EQ(+0.0, APFloat(APFloat::IEEEdouble(), "+0x0.0p1").convertToDouble());
789 EXPECT_EQ(-0.0, APFloat(APFloat::IEEEdouble(), "-0x0.0p1").convertToDouble());
790
791 EXPECT_EQ( 0.0, APFloat(APFloat::IEEEdouble(), "0x0.0p+1").convertToDouble());
792 EXPECT_EQ(+0.0, APFloat(APFloat::IEEEdouble(), "+0x0.0p+1").convertToDouble());
793 EXPECT_EQ(-0.0, APFloat(APFloat::IEEEdouble(), "-0x0.0p+1").convertToDouble());
794
795 EXPECT_EQ( 0.0, APFloat(APFloat::IEEEdouble(), "0x0.0p-1").convertToDouble());
796 EXPECT_EQ(+0.0, APFloat(APFloat::IEEEdouble(), "+0x0.0p-1").convertToDouble());
797 EXPECT_EQ(-0.0, APFloat(APFloat::IEEEdouble(), "-0x0.0p-1").convertToDouble());
798
799
800 EXPECT_EQ( 0.0, APFloat(APFloat::IEEEdouble(), "0x00000.p1").convertToDouble());
801 EXPECT_EQ( 0.0, APFloat(APFloat::IEEEdouble(), "0x0000.00000p1").convertToDouble());
802 EXPECT_EQ( 0.0, APFloat(APFloat::IEEEdouble(), "0x.00000p1").convertToDouble());
803 EXPECT_EQ( 0.0, APFloat(APFloat::IEEEdouble(), "0x0.p1").convertToDouble());
804 EXPECT_EQ( 0.0, APFloat(APFloat::IEEEdouble(), "0x0p1234").convertToDouble());
805 EXPECT_EQ(-0.0, APFloat(APFloat::IEEEdouble(), "-0x0p1234").convertToDouble());
806 EXPECT_EQ( 0.0, APFloat(APFloat::IEEEdouble(), "0x00000.p1234").convertToDouble());
807 EXPECT_EQ( 0.0, APFloat(APFloat::IEEEdouble(), "0x0000.00000p1234").convertToDouble());
808 EXPECT_EQ( 0.0, APFloat(APFloat::IEEEdouble(), "0x.00000p1234").convertToDouble());
809 EXPECT_EQ( 0.0, APFloat(APFloat::IEEEdouble(), "0x0.p1234").convertToDouble());
810810 }
811811
812812 TEST(APFloatTest, fromDecimalString) {
813 EXPECT_EQ(1.0, APFloat(APFloat::IEEEdouble, "1").convertToDouble());
814 EXPECT_EQ(2.0, APFloat(APFloat::IEEEdouble, "2.").convertToDouble());
815 EXPECT_EQ(0.5, APFloat(APFloat::IEEEdouble, ".5").convertToDouble());
816 EXPECT_EQ(1.0, APFloat(APFloat::IEEEdouble, "1.0").convertToDouble());
817 EXPECT_EQ(-2.0, APFloat(APFloat::IEEEdouble, "-2").convertToDouble());
818 EXPECT_EQ(-4.0, APFloat(APFloat::IEEEdouble, "-4.").convertToDouble());
819 EXPECT_EQ(-0.5, APFloat(APFloat::IEEEdouble, "-.5").convertToDouble());
820 EXPECT_EQ(-1.5, APFloat(APFloat::IEEEdouble, "-1.5").convertToDouble());
821 EXPECT_EQ(1.25e12, APFloat(APFloat::IEEEdouble, "1.25e12").convertToDouble());
822 EXPECT_EQ(1.25e+12, APFloat(APFloat::IEEEdouble, "1.25e+12").convertToDouble());
823 EXPECT_EQ(1.25e-12, APFloat(APFloat::IEEEdouble, "1.25e-12").convertToDouble());
824 EXPECT_EQ(1024.0, APFloat(APFloat::IEEEdouble, "1024.").convertToDouble());
825 EXPECT_EQ(1024.05, APFloat(APFloat::IEEEdouble, "1024.05000").convertToDouble());
826 EXPECT_EQ(0.05, APFloat(APFloat::IEEEdouble, ".05000").convertToDouble());
827 EXPECT_EQ(2.0, APFloat(APFloat::IEEEdouble, "2.").convertToDouble());
828 EXPECT_EQ(2.0e2, APFloat(APFloat::IEEEdouble, "2.e2").convertToDouble());
829 EXPECT_EQ(2.0e+2, APFloat(APFloat::IEEEdouble, "2.e+2").convertToDouble());
830 EXPECT_EQ(2.0e-2, APFloat(APFloat::IEEEdouble, "2.e-2").convertToDouble());
831 EXPECT_EQ(2.05e2, APFloat(APFloat::IEEEdouble, "002.05000e2").convertToDouble());
832 EXPECT_EQ(2.05e+2, APFloat(APFloat::IEEEdouble, "002.05000e+2").convertToDouble());
833 EXPECT_EQ(2.05e-2, APFloat(APFloat::IEEEdouble, "002.05000e-2").convertToDouble());
834 EXPECT_EQ(2.05e12, APFloat(APFloat::IEEEdouble, "002.05000e12").convertToDouble());
835 EXPECT_EQ(2.05e+12, APFloat(APFloat::IEEEdouble, "002.05000e+12").convertToDouble());
836 EXPECT_EQ(2.05e-12, APFloat(APFloat::IEEEdouble, "002.05000e-12").convertToDouble());
813 EXPECT_EQ(1.0, APFloat(APFloat::IEEEdouble(), "1").convertToDouble());
814 EXPECT_EQ(2.0, APFloat(APFloat::IEEEdouble(), "2.").convertToDouble());
815 EXPECT_EQ(0.5, APFloat(APFloat::IEEEdouble(), ".5").convertToDouble());
816 EXPECT_EQ(1.0, APFloat(APFloat::IEEEdouble(), "1.0").convertToDouble());
817 EXPECT_EQ(-2.0, APFloat(APFloat::IEEEdouble(), "-2").convertToDouble());
818 EXPECT_EQ(-4.0, APFloat(APFloat::IEEEdouble(), "-4.").convertToDouble());
819 EXPECT_EQ(-0.5, APFloat(APFloat::IEEEdouble(), "-.5").convertToDouble());
820 EXPECT_EQ(-1.5, APFloat(APFloat::IEEEdouble(), "-1.5").convertToDouble());
821 EXPECT_EQ(1.25e12, APFloat(APFloat::IEEEdouble(), "1.25e12").convertToDouble());
822 EXPECT_EQ(1.25e+12, APFloat(APFloat::IEEEdouble(), "1.25e+12").convertToDouble());
823 EXPECT_EQ(1.25e-12, APFloat(APFloat::IEEEdouble(), "1.25e-12").convertToDouble());
824 EXPECT_EQ(1024.0, APFloat(APFloat::IEEEdouble(), "1024.").convertToDouble());
825 EXPECT_EQ(1024.05, APFloat(APFloat::IEEEdouble(), "1024.05000").convertToDouble());
826 EXPECT_EQ(0.05, APFloat(APFloat::IEEEdouble(), ".05000").convertToDouble());
827 EXPECT_EQ(2.0, APFloat(APFloat::IEEEdouble(), "2.").convertToDouble());
828 EXPECT_EQ(2.0e2, APFloat(APFloat::IEEEdouble(), "2.e2").convertToDouble());
829 EXPECT_EQ(2.0e+2, APFloat(APFloat::IEEEdouble(), "2.e+2").convertToDouble());
830 EXPECT_EQ(2.0e-2, APFloat(APFloat::IEEEdouble(), "2.e-2").convertToDouble());
831 EXPECT_EQ(2.05e2, APFloat(APFloat::IEEEdouble(), "002.05000e2").convertToDouble());
832 EXPECT_EQ(2.05e+2, APFloat(APFloat::IEEEdouble(), "002.05000e+2").convertToDouble());
833 EXPECT_EQ(2.05e-2, APFloat(APFloat::IEEEdouble(), "002.05000e-2").convertToDouble());
834 EXPECT_EQ(2.05e12, APFloat(APFloat::IEEEdouble(), "002.05000e12").convertToDouble());
835 EXPECT_EQ(2.05e+12, APFloat(APFloat::IEEEdouble(), "002.05000e+12").convertToDouble());
836 EXPECT_EQ(2.05e-12, APFloat(APFloat::IEEEdouble(), "002.05000e-12").convertToDouble());
837837
838838 // These are "carefully selected" to overflow the fast log-base
839839 // calculations in APFloat.cpp
840 EXPECT_TRUE(APFloat(APFloat::IEEEdouble, "99e99999").isInfinity());
841 EXPECT_TRUE(APFloat(APFloat::IEEEdouble, "-99e99999").isInfinity());
842 EXPECT_TRUE(APFloat(APFloat::IEEEdouble, "1e-99999").isPosZero());
843 EXPECT_TRUE(APFloat(APFloat::IEEEdouble, "-1e-99999").isNegZero());
840 EXPECT_TRUE(APFloat(APFloat::IEEEdouble(), "99e99999").isInfinity());
841 EXPECT_TRUE(APFloat(APFloat::IEEEdouble(), "-99e99999").isInfinity());
842 EXPECT_TRUE(APFloat(APFloat::IEEEdouble(), "1e-99999").isPosZero());
843 EXPECT_TRUE(APFloat(APFloat::IEEEdouble(), "-1e-99999").isNegZero());
844844
845845 EXPECT_EQ(2.71828, convertToDoubleFromString("2.71828"));
846846 }
847847
848848 TEST(APFloatTest, fromHexadecimalString) {
849 EXPECT_EQ( 1.0, APFloat(APFloat::IEEEdouble, "0x1p0").convertToDouble());
850 EXPECT_EQ(+1.0, APFloat(APFloat::IEEEdouble, "+0x1p0").convertToDouble());
851 EXPECT_EQ(-1.0, APFloat(APFloat::IEEEdouble, "-0x1p0").convertToDouble());
852
853 EXPECT_EQ( 1.0, APFloat(APFloat::IEEEdouble, "0x1p+0").convertToDouble());
854 EXPECT_EQ(+1.0, APFloat(APFloat::IEEEdouble, "+0x1p+0").convertToDouble());
855 EXPECT_EQ(-1.0, APFloat(APFloat::IEEEdouble, "-0x1p+0").convertToDouble());
856
857 EXPECT_EQ( 1.0, APFloat(APFloat::IEEEdouble, "0x1p-0").convertToDouble());
858 EXPECT_EQ(+1.0, APFloat(APFloat::IEEEdouble, "+0x1p-0").convertToDouble());
859 EXPECT_EQ(-1.0, APFloat(APFloat::IEEEdouble, "-0x1p-0").convertToDouble());
860
861
862 EXPECT_EQ( 2.0, APFloat(APFloat::IEEEdouble, "0x1p1").convertToDouble());
863 EXPECT_EQ(+2.0, APFloat(APFloat::IEEEdouble, "+0x1p1").convertToDouble());
864 EXPECT_EQ(-2.0, APFloat(APFloat::IEEEdouble, "-0x1p1").convertToDouble());
865
866 EXPECT_EQ( 2.0, APFloat(APFloat::IEEEdouble, "0x1p+1").convertToDouble());
867 EXPECT_EQ(+2.0, APFloat(APFloat::IEEEdouble, "+0x1p+1").convertToDouble());
868 EXPECT_EQ(-2.0, APFloat(APFloat::IEEEdouble, "-0x1p+1").convertToDouble());
869
870 EXPECT_EQ( 0.5, APFloat(APFloat::IEEEdouble, "0x1p-1").convertToDouble());
871 EXPECT_EQ(+0.5, APFloat(APFloat::IEEEdouble, "+0x1p-1").convertToDouble());
872 EXPECT_EQ(-0.5, APFloat(APFloat::IEEEdouble, "-0x1p-1").convertToDouble());
873
874
875 EXPECT_EQ( 3.0, APFloat(APFloat::IEEEdouble, "0x1.8p1").convertToDouble());
876 EXPECT_EQ(+3.0, APFloat(APFloat::IEEEdouble, "+0x1.8p1").convertToDouble());
877 EXPECT_EQ(-3.0, APFloat(APFloat::IEEEdouble, "-0x1.8p1").convertToDouble());
878
879 EXPECT_EQ( 3.0, APFloat(APFloat::IEEEdouble, "0x1.8p+1").convertToDouble());
880 EXPECT_EQ(+3.0, APFloat(APFloat::IEEEdouble, "+0x1.8p+1").convertToDouble());
881 EXPECT_EQ(-3.0, APFloat(APFloat::IEEEdouble, "-0x1.8p+1").convertToDouble());
882
883 EXPECT_EQ( 0.75, APFloat(APFloat::IEEEdouble, "0x1.8p-1").convertToDouble());
884 EXPECT_EQ(+0.75, APFloat(APFloat::IEEEdouble, "+0x1.8p-1").convertToDouble());
885 EXPECT_EQ(-0.75, APFloat(APFloat::IEEEdouble, "-0x1.8p-1").convertToDouble());
886
887
888 EXPECT_EQ( 8192.0, APFloat(APFloat::IEEEdouble, "0x1000.000p1").convertToDouble());
889 EXPECT_EQ(+8192.0, APFloat(APFloat::IEEEdouble, "+0x1000.000p1").convertToDouble());
890 EXPECT_EQ(-8192.0, APFloat(APFloat::IEEEdouble, "-0x1000.000p1").convertToDouble());
891
892 EXPECT_EQ( 8192.0, APFloat(APFloat::IEEEdouble, "0x1000.000p+1").convertToDouble());
893 EXPECT_EQ(+8192.0, APFloat(APFloat::IEEEdouble, "+0x1000.000p+1").convertToDouble());
894 EXPECT_EQ(-8192.0, APFloat(APFloat::IEEEdouble, "-0x1000.000p+1").convertToDouble());
895
896 EXPECT_EQ( 2048.0, APFloat(APFloat::IEEEdouble, "0x1000.000p-1").convertToDouble());
897 EXPECT_EQ(+2048.0, APFloat(APFloat::IEEEdouble, "+0x1000.000p-1").convertToDouble());
898 EXPECT_EQ(-2048.0, APFloat(APFloat::IEEEdouble, "-0x1000.000p-1").convertToDouble());
899
900
901 EXPECT_EQ( 8192.0, APFloat(APFloat::IEEEdouble, "0x1000p1").convertToDouble());
902 EXPECT_EQ(+8192.0, APFloat(APFloat::IEEEdouble, "+0x1000p1").convertToDouble());
903 EXPECT_EQ(-8192.0, APFloat(APFloat::IEEEdouble, "-0x1000p1").convertToDouble());
904
905 EXPECT_EQ( 8192.0, APFloat(APFloat::IEEEdouble, "0x1000p+1").convertToDouble());
906 EXPECT_EQ(+8192.0, APFloat(APFloat::IEEEdouble, "+0x1000p+1").convertToDouble());
907 EXPECT_EQ(-8192.0, APFloat(APFloat::IEEEdouble, "-0x1000p+1").convertToDouble());
908
909 EXPECT_EQ( 2048.0, APFloat(APFloat::IEEEdouble, "0x1000p-1").convertToDouble());
910 EXPECT_EQ(+2048.0, APFloat(APFloat::IEEEdouble, "+0x1000p-1").convertToDouble());
911 EXPECT_EQ(-2048.0, APFloat(APFloat::IEEEdouble, "-0x1000p-1").convertToDouble());
912
913
914 EXPECT_EQ( 16384.0, APFloat(APFloat::IEEEdouble, "0x10p10").convertToDouble());
915 EXPECT_EQ(+16384.0, APFloat(APFloat::IEEEdouble, "+0x10p10").convertToDouble());
916 EXPECT_EQ(-16384.0, APFloat(APFloat::IEEEdouble, "-0x10p10").convertToDouble());
917
918 EXPECT_EQ( 16384.0, APFloat(APFloat::IEEEdouble, "0x10p+10").convertToDouble());
919 EXPECT_EQ(+16384.0, APFloat(APFloat::IEEEdouble, "+0x10p+10").convertToDouble());
920 EXPECT_EQ(-16384.0, APFloat(APFloat::IEEEdouble, "-0x10p+10").convertToDouble());
921
922 EXPECT_EQ( 0.015625, APFloat(APFloat::IEEEdouble, "0x10p-10").convertToDouble());
923 EXPECT_EQ(+0.015625, APFloat(APFloat::IEEEdouble, "+0x10p-10").convertToDouble());
924 EXPECT_EQ(-0.015625, APFloat(APFloat::IEEEdouble, "-0x10p-10").convertToDouble());
925
926 EXPECT_EQ(1.0625, APFloat(APFloat::IEEEdouble, "0x1.1p0").convertToDouble());
927 EXPECT_EQ(1.0, APFloat(APFloat::IEEEdouble, "0x1p0").convertToDouble());
849 EXPECT_EQ( 1.0, APFloat(APFloat::IEEEdouble(), "0x1p0").convertToDouble());
850 EXPECT_EQ(+1.0, APFloat(APFloat::IEEEdouble(), "+0x1p0").convertToDouble());
851 EXPECT_EQ(-1.0, APFloat(APFloat::IEEEdouble(), "-0x1p0").convertToDouble());
852
853 EXPECT_EQ( 1.0, APFloat(APFloat::IEEEdouble(), "0x1p+0").convertToDouble());
854 EXPECT_EQ(+1.0, APFloat(APFloat::IEEEdouble(), "+0x1p+0").convertToDouble());
855 EXPECT_EQ(-1.0, APFloat(APFloat::IEEEdouble(), "-0x1p+0").convertToDouble());
856
857 EXPECT_EQ( 1.0, APFloat(APFloat::IEEEdouble(), "0x1p-0").convertToDouble());
858 EXPECT_EQ(+1.0, APFloat(APFloat::IEEEdouble(), "+0x1p-0").convertToDouble());
859 EXPECT_EQ(-1.0, APFloat(APFloat::IEEEdouble(), "-0x1p-0").convertToDouble());
860
861
862 EXPECT_EQ( 2.0, APFloat(APFloat::IEEEdouble(), "0x1p1").convertToDouble());
863 EXPECT_EQ(+2.0, APFloat(APFloat::IEEEdouble(), "+0x1p1").convertToDouble());
864 EXPECT_EQ(-2.0, APFloat(APFloat::IEEEdouble(), "-0x1p1").convertToDouble());
865
866 EXPECT_EQ( 2.0, APFloat(APFloat::IEEEdouble(), "0x1p+1").convertToDouble());
867 EXPECT_EQ(+2.0, APFloat(APFloat::IEEEdouble(), "+0x1p+1").convertToDouble());
868 EXPECT_EQ(-2.0, APFloat(APFloat::IEEEdouble(), "-0x1p+1").convertToDouble());
869
870 EXPECT_EQ( 0.5, APFloat(APFloat::IEEEdouble(), "0x1p-1").convertToDouble());
871 EXPECT_EQ(+0.5, APFloat(APFloat::IEEEdouble(), "+0x1p-1").convertToDouble());
872 EXPECT_EQ(-0.5, APFloat(APFloat::IEEEdouble(), "-0x1p-1").convertToDouble());
873
874
875 EXPECT_EQ( 3.0, APFloat(APFloat::IEEEdouble(), "0x1.8p1").convertToDouble());
876 EXPECT_EQ(+3.0, APFloat(APFloat::IEEEdouble(), "+0x1.8p1").convertToDouble());
877 EXPECT_EQ(-3.0, APFloat(APFloat::IEEEdouble(), "-0x1.8p1").convertToDouble());
878
879 EXPECT_EQ( 3.0, APFloat(APFloat::IEEEdouble(), "0x1.8p+1").convertToDouble());
880 EXPECT_EQ(+3.0, APFloat(APFloat::IEEEdouble(), "+0x1.8p+1").convertToDouble());
881 EXPECT_EQ(-3.0, APFloat(APFloat::IEEEdouble(), "-0x1.8p+1").convertToDouble());
882
883 EXPECT_EQ( 0.75, APFloat(APFloat::IEEEdouble(), "0x1.8p-1").convertToDouble());
884 EXPECT_EQ(+0.75, APFloat(APFloat::IEEEdouble(), "+0x1.8p-1").convertToDouble());
885 EXPECT_EQ(-0.75, APFloat(APFloat::IEEEdouble(), "-0x1.8p-1").convertToDouble());
886
887
888 EXPECT_EQ( 8192.0, APFloat(APFloat::IEEEdouble(), "0x1000.000p1").convertToDouble());
889 EXPECT_EQ(+8192.0, APFloat(APFloat::IEEEdouble(), "+0x1000.000p1").convertToDouble());
890 EXPECT_EQ(-8192.0, APFloat(APFloat::IEEEdouble(), "-0x1000.000p1").convertToDouble());
891
892 EXPECT_EQ( 8192.0, APFloat(APFloat::IEEEdouble(), "0x1000.000p+1").convertToDouble());
893 EXPECT_EQ(+8192.0, APFloat(APFloat::IEEEdouble(), "+0x1000.000p+1").convertToDouble());
894 EXPECT_EQ(-8192.0, APFloat(APFloat::IEEEdouble(), "-0x1000.000p+1").convertToDouble());
895
896 EXPECT_EQ( 2048.0, APFloat(APFloat::IEEEdouble(), "0x1000.000p-1").convertToDouble());
897 EXPECT_EQ(+2048.0, APFloat(APFloat::IEEEdouble(), "+0x1000.000p-1").convertToDouble());
898 EXPECT_EQ(-2048.0, APFloat(APFloat::IEEEdouble(), "-0x1000.000p-1").convertToDouble());
899
900
901 EXPECT_EQ( 8192.0, APFloat(APFloat::IEEEdouble(), "0x1000p1").convertToDouble());
902 EXPECT_EQ(+8192.0, APFloat(APFloat::IEEEdouble(), "+0x1000p1").convertToDouble());
903 EXPECT_EQ(-8192.0, APFloat(APFloat::IEEEdouble(), "-0x1000p1").convertToDouble());
904
905 EXPECT_EQ( 8192.0, APFloat(APFloat::IEEEdouble(), "0x1000p+1").convertToDouble());
906 EXPECT_EQ(+8192.0, APFloat(APFloat::IEEEdouble(), "+0x1000p+1").convertToDouble());
907 EXPECT_EQ(-8192.0, APFloat(APFloat::IEEEdouble(), "-0x1000p+1").convertToDouble());
908
909 EXPECT_EQ( 2048.0, APFloat(APFloat::IEEEdouble(), "0x1000p-1").convertToDouble());
910 EXPECT_EQ(+2048.0, APFloat(APFloat::IEEEdouble(), "+0x1000p-1").convertToDouble());
911 EXPECT_EQ(-2048.0, APFloat(APFloat::IEEEdouble(), "-0x1000p-1").convertToDouble());
912
913
914 EXPECT_EQ( 16384.0, APFloat(APFloat::IEEEdouble(), "0x10p10").convertToDouble());
915 EXPECT_EQ(+16384.0, APFloat(APFloat::IEEEdouble(), "+0x10p10").convertToDouble());
916 EXPECT_EQ(-16384.0, APFloat(APFloat::IEEEdouble(), "-0x10p10").convertToDouble());
917
918 EXPECT_EQ( 16384.0, APFloat(APFloat::IEEEdouble(), "0x10p+10").convertToDouble());
919 EXPECT_EQ(+16384.0, APFloat(APFloat::IEEEdouble(), "+0x10p+10").convertToDouble());
920 EXPECT_EQ(-16384.0, APFloat(APFloat::IEEEdouble(), "-0x10p+10").convertToDouble());
921
922 EXPECT_EQ( 0.015625, APFloat(APFloat::IEEEdouble(), "0x10p-10").convertToDouble());
923 EXPECT_EQ(+0.015625, APFloat(APFloat::IEEEdouble(), "+0x10p-10").convertToDouble());
924 EXPECT_EQ(-0.015625, APFloat(APFloat::IEEEdouble(), "-0x10p-10").convertToDouble());
925
926 EXPECT_EQ(1.0625, APFloat(APFloat::IEEEdouble(), "0x1.1p0").convertToDouble());
927 EXPECT_EQ(1.0, APFloat(APFloat::IEEEdouble(), "0x1p0").convertToDouble());
928928
929929 EXPECT_EQ(convertToDoubleFromString("0x1p-150"),
930930 convertToDoubleFromString("+0x800000000000000001.p-221"));
953953 APSInt result(5, /*isUnsigned=*/true);
954954
955955 EXPECT_EQ(APFloat::opOK,
956 APFloat(APFloat::IEEEdouble, "10")
956 APFloat(APFloat::IEEEdouble(), "10")
957957 .convertToInteger(result, APFloat::rmTowardZero, &isExact));
958958 EXPECT_TRUE(isExact);
959959 EXPECT_EQ(APSInt(APInt(5, 10), true), result);
960960
961961 EXPECT_EQ(APFloat::opInvalidOp,
962 APFloat(APFloat::IEEEdouble, "-10")
962 APFloat(APFloat::IEEEdouble(), "-10")
963963 .convertToInteger(result, APFloat::rmTowardZero, &isExact));
964964 EXPECT_FALSE(isExact);
965965 EXPECT_EQ(APSInt::getMinValue(5, true), result);
966966
967967 EXPECT_EQ(APFloat::opInvalidOp,
968 APFloat(APFloat::IEEEdouble, "32")
968 APFloat(APFloat::IEEEdouble(), "32")
969969 .convertToInteger(result, APFloat::rmTowardZero, &isExact));
970970 EXPECT_FALSE(isExact);
971971 EXPECT_EQ(APSInt::getMaxValue(5, true), result);
972972
973973 EXPECT_EQ(APFloat::opInexact,
974 APFloat(APFloat::IEEEdouble, "7.9")
974 APFloat(APFloat::IEEEdouble(), "7.9")
975975 .convertToInteger(result, APFloat::rmTowardZero, &isExact));
976976 EXPECT_FALSE(isExact);
977977 EXPECT_EQ(APSInt(APInt(5, 7), true), result);
978978
979979 result.setIsUnsigned(false);
980980 EXPECT_EQ(APFloat::opOK,
981 APFloat(APFloat::IEEEdouble, "-10")
981 APFloat(APFloat::IEEEdouble(), "-10")
982982 .convertToInteger(result, APFloat::rmTowardZero, &isExact));
983983 EXPECT_TRUE(isExact);
984984 EXPECT_EQ(APSInt(APInt(5, -10, true), false), result);
985985
986986 EXPECT_EQ(APFloat::opInvalidOp,
987 APFloat(APFloat::IEEEdouble, "-17")
987 APFloat(APFloat::IEEEdouble(), "-17")
988988 .convertToInteger(result, APFloat::rmTowardZero, &isExact));
989989 EXPECT_FALSE(isExact);
990990 EXPECT_EQ(APSInt::getMinValue(5, false), result);
991991
992992 EXPECT_EQ(APFloat::opInvalidOp,
993 APFloat(APFloat::IEEEdouble, "16")
993 APFloat(APFloat::IEEEdouble(), "16")
994994 .convertToInteger(result, APFloat::rmTowardZero, &isExact));
995995 EXPECT_FALSE(isExact);
996996 EXPECT_EQ(APSInt::getMaxValue(5, false), result);
10061006 }
10071007
10081008 TEST(APFloatTest, makeNaN) {
1009 ASSERT_EQ(0x7fc00000, nanbits(APFloat::IEEEsingle, false, false, 0));
1010 ASSERT_EQ(0xffc00000, nanbits(APFloat::IEEEsingle, false, true, 0));
1011 ASSERT_EQ(0x7fc0ae72, nanbits(APFloat::IEEEsingle, false, false, 0xae72));
1012 ASSERT_EQ(0x7fffae72, nanbits(APFloat::IEEEsingle, false, false, 0xffffae72));
1013 ASSERT_EQ(0x7fa00000, nanbits(APFloat::IEEEsingle, true, false, 0));
1014 ASSERT_EQ(0xffa00000, nanbits(APFloat::IEEEsingle, true, true, 0));
1015 ASSERT_EQ(0x7f80ae72, nanbits(APFloat::IEEEsingle, true, false, 0xae72));
1016 ASSERT_EQ(0x7fbfae72, nanbits(APFloat::IEEEsingle, true, false, 0xffffae72));
1017
1018 ASSERT_EQ(0x7ff8000000000000ULL, nanbits(APFloat::IEEEdouble, false, false, 0));
1019 ASSERT_EQ(0xfff8000000000000ULL, nanbits(APFloat::IEEEdouble, false, true, 0));
1020 ASSERT_EQ(0x7ff800000000ae72ULL, nanbits(APFloat::IEEEdouble, false, false, 0xae72));
1021 ASSERT_EQ(0x7fffffffffffae72ULL, nanbits(APFloat::IEEEdouble, false, false, 0xffffffffffffae72ULL));
1022 ASSERT_EQ(0x7ff4000000000000ULL, nanbits(APFloat::IEEEdouble, true, false, 0));
1023 ASSERT_EQ(0xfff4000000000000ULL, nanbits(APFloat::IEEEdouble, true, true, 0));
1024 ASSERT_EQ(0x7ff000000000ae72ULL, nanbits(APFloat::IEEEdouble, true, false, 0xae72));
1025 ASSERT_EQ(0x7ff7ffffffffae72ULL, nanbits(APFloat::IEEEdouble, true, false, 0xffffffffffffae72ULL));
1009 ASSERT_EQ(0x7fc00000, nanbits(APFloat::IEEEsingle(), false, false, 0));
1010 ASSERT_EQ(0xffc00000, nanbits(APFloat::IEEEsingle(), false, true, 0));
1011 ASSERT_EQ(0x7fc0ae72, nanbits(APFloat::IEEEsingle(), false, false, 0xae72));
1012 ASSERT_EQ(0x7fffae72, nanbits(APFloat::IEEEsingle(), false, false, 0xffffae72));
1013 ASSERT_EQ(0x7fa00000, nanbits(APFloat::IEEEsingle(), true, false, 0));
1014 ASSERT_EQ(0xffa00000, nanbits(APFloat::IEEEsingle(), true, true, 0));
1015 ASSERT_EQ(0x7f80ae72, nanbits(APFloat::IEEEsingle(), true, false, 0xae72));
1016 ASSERT_EQ(0x7fbfae72, nanbits(APFloat::IEEEsingle(), true, false, 0xffffae72));
1017
1018 ASSERT_EQ(0x7ff8000000000000ULL, nanbits(APFloat::IEEEdouble(), false, false, 0));
1019 ASSERT_EQ(0xfff8000000000000ULL, nanbits(APFloat::IEEEdouble(), false, true, 0));
1020 ASSERT_EQ(0x7ff800000000ae72ULL, nanbits(APFloat::IEEEdouble(), false, false, 0xae72));
1021 ASSERT_EQ(0x7fffffffffffae72ULL, nanbits(APFloat::IEEEdouble(), false, false, 0xffffffffffffae72ULL));
1022 ASSERT_EQ(0x7ff4000000000000ULL, nanbits(APFloat::IEEEdouble(), true, false, 0));
1023 ASSERT_EQ(0xfff4000000000000ULL, nanbits(APFloat::IEEEdouble(), true, true, 0));
1024 ASSERT_EQ(0x7ff000000000ae72ULL, nanbits(APFloat::IEEEdouble(), true, false, 0xae72));
1025 ASSERT_EQ(0x7ff7ffffffffae72ULL, nanbits(APFloat::IEEEdouble(), true, false, 0xffffffffffffae72ULL));
10261026 }
10271027
10281028 #ifdef GTEST_HAS_DEATH_TEST
10291029 #ifndef NDEBUG
10301030 TEST(APFloatTest, SemanticsDeath) {
1031 EXPECT_DEATH(APFloat(APFloat::IEEEsingle, 0.0f).convertToDouble(), "Float semantics are not IEEEdouble");
1032 EXPECT_DEATH(APFloat(APFloat::IEEEdouble, 0.0 ).convertToFloat(), "Float semantics are not IEEEsingle");
1031 EXPECT_DEATH(APFloat(APFloat::IEEEsingle(), 0.0f).convertToDouble(), "Float semantics are not IEEEdouble");
1032 EXPECT_DEATH(APFloat(APFloat::IEEEdouble(), 0.0 ).convertToFloat(), "Float semantics are not IEEEsingle");
10331033 }
10341034
10351035 TEST(APFloatTest, StringDecimalDeath) {
1036 EXPECT_DEATH(APFloat(APFloat::IEEEdouble, ""), "Invalid string length");
1037 EXPECT_DEATH(APFloat(APFloat::IEEEdouble, "+"), "String has no digits");
1038 EXPECT_DEATH(APFloat(APFloat::IEEEdouble, "-"), "String has no digits");
1039
1040 EXPECT_DEATH(APFloat(APFloat::IEEEdouble, StringRef("\0", 1)), "Invalid character in significand");
1041 EXPECT_DEATH(APFloat(APFloat::IEEEdouble, StringRef("1\0", 2)), "Invalid character in significand");
1042 EXPECT_DEATH(APFloat(APFloat::IEEEdouble, StringRef("1\02", 3)), "Invalid character in significand");
1043 EXPECT_DEATH(APFloat(APFloat::IEEEdouble, StringRef("1\02e1", 5)), "Invalid character in significand");
1044 EXPECT_DEATH(APFloat(APFloat::IEEEdouble, StringRef("1e\0", 3)), "Invalid character in exponent");
1045 EXPECT_DEATH(APFloat(APFloat::IEEEdouble, StringRef("1e1\0", 4)), "Invalid character in exponent");
1046 EXPECT_DEATH(APFloat(APFloat::IEEEdouble, StringRef("1e1\02", 5)), "Invalid character in exponent");
1047
1048 EXPECT_DEATH(APFloat(APFloat::IEEEdouble, "1.0f"), "Invalid character in significand");
1049
1050 EXPECT_DEATH(APFloat(APFloat::IEEEdouble, ".."), "String contains multiple dots");
1051 EXPECT_DEATH(APFloat(APFloat::IEEEdouble, "..0"), "String contains multiple dots");
1052 EXPECT_DEATH(APFloat(APFloat::IEEEdouble, "1.0.0"), "String contains multiple dots");
1036 EXPECT_DEATH(APFloat(APFloat::IEEEdouble(), ""), "Invalid string length");
1037 EXPECT_DEATH(APFloat(APFloat::IEEEdouble(), "+"), "String has no digits");
1038 EXPECT_DEATH(APFloat(APFloat::IEEEdouble(), "-"), "String has no digits");
1039
1040 EXPECT_DEATH(APFloat(APFloat::IEEEdouble(), StringRef("\0", 1)), "Invalid character in significand");
1041 EXPECT_DEATH(APFloat(APFloat::IEEEdouble(), StringRef("1\0", 2)), "Invalid character in significand");
1042 EXPECT_DEATH(APFloat(APFloat::IEEEdouble(), StringRef("1\02", 3)), "Invalid character in significand");
1043 EXPECT_DEATH(APFloat(APFloat::IEEEdouble(), StringRef("1\02e1", 5)), "Invalid character in significand");
1044 EXPECT_DEATH(APFloat(APFloat::IEEEdouble(), StringRef("1e\0", 3)), "Invalid character in exponent");
1045 EXPECT_DEATH(APFloat(APFloat::IEEEdouble(), StringRef("1e1\0", 4)), "Invalid character in exponent");
1046 EXPECT_DEATH(APFloat(APFloat::IEEEdouble(), StringRef("1e1\02", 5)), "Invalid character in exponent");
1047
1048 EXPECT_DEATH(APFloat(APFloat::IEEEdouble(), "1.0f"), "Invalid character in significand");
1049
1050 EXPECT_DEATH(APFloat(APFloat::IEEEdouble(), ".."), "String contains multiple dots");
1051 EXPECT_DEATH(APFloat(APFloat::IEEEdouble(), "..0"), "String contains multiple dots");
1052 EXPECT_DEATH(APFloat(APFloat::IEEEdouble(), "1.0.0"), "String contains multiple dots");
10531053 }
10541054
10551055 TEST(APFloatTest, StringDecimalSignificandDeath) {
1056 EXPECT_DEATH(APFloat(APFloat::IEEEdouble, "."), "Significand has no digits");
1057 EXPECT_DEATH(APFloat(APFloat::IEEEdouble, "+."), "Significand has no digits");
1058 EXPECT_DEATH(APFloat(APFloat::IEEEdouble, "-."), "Significand has no digits");
1059
1060
1061 EXPECT_DEATH(APFloat(APFloat::IEEEdouble, "e"), "Significand has no digits");
1062 EXPECT_DEATH(APFloat(APFloat::IEEEdouble, "+e"), "Significand has no digits");
1063 EXPECT_DEATH(APFloat(APFloat::IEEEdouble, "-e"), "Significand has no digits");
1064
1065 EXPECT_DEATH(APFloat(APFloat::IEEEdouble, "e1"), "Significand has no digits");
1066 EXPECT_DEATH(APFloat(APFloat::IEEEdouble, "+e1"), "Significand has no digits");
1067 EXPECT_DEATH(APFloat(APFloat::IEEEdouble, "-e1"), "Significand has no digits");
1068
1069 EXPECT_DEATH(APFloat(APFloat::IEEEdouble, ".e1"), "Significand has no digits");
1070 EXPECT_DEATH(APFloat(APFloat::IEEEdouble, "+.e1"), "Significand has no digits");
1071 EXPECT_DEATH(APFloat(APFloat::IEEEdouble, "-.e1"), "Significand has no digits");
1072
1073
1074 EXPECT_DEATH(APFloat(APFloat::IEEEdouble, ".e"), "Significand has no digits");
1075 EXPECT_DEATH(APFloat(APFloat::IEEEdouble, "+.e"), "Significand has no digits");
1076 EXPECT_DEATH(APFloat(APFloat::IEEEdouble, "-.e"), "Significand has no digits");
1056 EXPECT_DEATH(APFloat(APFloat::IEEEdouble(), "."), "Significand has no digits");
1057 EXPECT_DEATH(APFloat(APFloat::IEEEdouble(), "+."), "Significand has no digits");
1058 EXPECT_DEATH(APFloat(APFloat::IEEEdouble(), "-."), "Significand has no digits");
1059
1060
1061 EXPECT_DEATH(APFloat(APFloat::IEEEdouble(), "e"), "Significand has no digits");
1062 EXPECT_DEATH(APFloat(APFloat::IEEEdouble(), "+e"), "Significand has no digits");
1063 EXPECT_DEATH(APFloat(APFloat::IEEEdouble(), "-e"), "Significand has no digits");
1064
1065 EXPECT_DEATH(APFloat(APFloat::IEEEdouble(), "e1"), "Significand has no digits");
1066 EXPECT_DEATH(APFloat(APFloat::IEEEdouble(), "+e1"), "Significand has no digits");
1067 EXPECT_DEATH(APFloat(APFloat::IEEEdouble(), "-e1"), "Significand has no digits");
1068
1069 EXPECT_DEATH(APFloat(APFloat::IEEEdouble(), ".e1"), "Significand has no digits");
1070 EXPECT_DEATH(APFloat(APFloat::IEEEdouble(), "+.e1"), "Significand has no digits");
1071 EXPECT_DEATH(APFloat(APFloat::IEEEdouble(), "-.e1"), "Significand has no digits");
1072
1073
1074 EXPECT_DEATH(APFloat(APFloat::IEEEdouble(), ".e"), "Significand has no digits");
1075 EXPECT_DEATH(APFloat(APFloat::IEEEdouble(), "+.e"), "Significand has no digits");
1076 EXPECT_DEATH(APFloat(APFloat::IEEEdouble(), "-.e"), "Significand has no digits");
10771077 }
10781078
10791079 TEST(APFloatTest, StringDecimalExponentDeath) {
1080 EXPECT_DEATH(APFloat(APFloat::IEEEdouble, "1e"), "Exponent has no digits");
1081 EXPECT_DEATH(APFloat(APFloat::IEEEdouble, "+1e"), "Exponent has no digits");
1082 EXPECT_DEATH(APFloat(APFloat::IEEEdouble, "-1e"), "Exponent has no digits");
1083
1084 EXPECT_DEATH(APFloat(APFloat::IEEEdouble, "1.e"), "Exponent has no digits");
1085 EXPECT_DEATH(APFloat(APFloat::IEEEdouble, "+1.e"), "Exponent has no digits");
1086 EXPECT_DEATH(APFloat(APFloat::IEEEdouble, "-1.e"), "Exponent has no digits");
1087
1088 EXPECT_DEATH(APFloat(APFloat::IEEEdouble, ".1e"), "Exponent has no digits");
1089 EXPECT_DEATH(APFloat(APFloat::IEEEdouble, "+.1e"), "Exponent has no digits");
1090 EXPECT_DEATH(APFloat(APFloat::IEEEdouble, "-.1e"), "Exponent has no digits");
1091
1092 EXPECT_DEATH(APFloat(APFloat::IEEEdouble, "1.1e"), "Exponent has no digits");
1093 EXPECT_DEATH(APFloat(APFloat::IEEEdouble, "+1.1e"), "Exponent has no digits");
1094 EXPECT_DEATH(APFloat(APFloat::IEEEdouble, "-1.1e"), "Exponent has no digits");
1095
1096
1097 EXPECT_DEATH(APFloat(APFloat::IEEEdouble, "1e+"), "Exponent has no digits");
1098 EXPECT_DEATH(APFloat(APFloat::IEEEdouble, "1e-"), "Exponent has no digits");
1099
1100 EXPECT_DEATH(APFloat(APFloat::IEEEdouble, ".1e"), "Exponent has no digits");
1101 EXPECT_DEATH(APFloat(APFloat::IEEEdouble, ".1e+"), "Exponent has no digits");
1102 EXPECT_DEATH(APFloat(APFloat::IEEEdouble, ".1e-"), "Exponent has no digits");
1103
1104 EXPECT_DEATH(APFloat(APFloat::IEEEdouble, "1.0e"), "Exponent has no digits");
1105 EXPECT_DEATH(APFloat(APFloat::IEEEdouble, "1.0e+"), "Exponent has no digits");
1106 EXPECT_DEATH(APFloat(APFloat::IEEEdouble, "1.0e-"), "Exponent has no digits");
1080 EXPECT_DEATH(APFloat(APFloat::IEEEdouble(), "1e"), "Exponent has no digits");
1081 EXPECT_DEATH(APFloat(APFloat::IEEEdouble(), "+1e"), "Exponent has no digits");
1082 EXPECT_DEATH(APFloat(APFloat::IEEEdouble(), "-1e"), "Exponent has no digits");
1083
1084 EXPECT_DEATH(APFloat(APFloat::IEEEdouble(), "1.e"), "Exponent has no digits");
1085 EXPECT_DEATH(APFloat(APFloat::IEEEdouble(), "+1.e"), "Exponent has no digits");
1086 EXPECT_DEATH(APFloat(APFloat::IEEEdouble(), "-1.e"), "Exponent has no digits");
1087
1088 EXPECT_DEATH(APFloat(APFloat::IEEEdouble(), ".1e"), "Exponent has no digits");
1089 EXPECT_DEATH(APFloat(APFloat::IEEEdouble(), "+.1e"), "Exponent has no digits");
1090 EXPECT_DEATH(APFloat(APFloat::IEEEdouble(), "-.1e"), "Exponent has no digits");
1091
1092 EXPECT_DEATH(APFloat(APFloat::IEEEdouble(), "1.1e"), "Exponent has no digits");
1093 EXPECT_DEATH(APFloat(APFloat::IEEEdouble(), "+1.1e"), "Exponent has no digits");
1094 EXPECT_DEATH(APFloat(APFloat::IEEEdouble(), "-1.1e"), "Exponent has no digits");
1095
1096
1097 EXPECT_DEATH(APFloat(APFloat::IEEEdouble(), "1e+"), "Exponent has no digits");
1098 EXPECT_DEATH(APFloat(APFloat::IEEEdouble(), "1e-"), "Exponent has no digits");
1099
1100 EXPECT_DEATH(APFloat(APFloat::IEEEdouble(), ".1e"), "Exponent has no digits");
1101 EXPECT_DEATH(APFloat(APFloat::IEEEdouble(), ".1e+"), "Exponent has no digits");
1102 EXPECT_DEATH(APFloat(APFloat::IEEEdouble(), ".1e-"), "Exponent has no digits");
1103
1104 EXPECT_DEATH(APFloat(APFloat::IEEEdouble(), "1.0e"), "Exponent has no digits");
1105 EXPECT_DEATH(APFloat(APFloat::IEEEdouble(), "1.0e+"), "Exponent has no digits");
1106 EXPECT_DEATH(APFloat(APFloat::IEEEdouble(), "1.0e-"), "Exponent has no digits");
11071107 }
11081108
11091109 TEST(APFloatTest, StringHexadecimalDeath) {
1110 EXPECT_DEATH(APFloat(APFloat::IEEEdouble, "0x"), "Invalid string");
1111 EXPECT_DEATH(APFloat(APFloat::IEEEdouble, "+0x"), "Invalid string");
1112 EXPECT_DEATH(APFloat(APFloat::IEEEdouble, "-0x"), "Invalid string");
1113
1114 EXPECT_DEATH(APFloat(APFloat::IEEEdouble, "0x0"), "Hex strings require an exponent");
1115 EXPECT_DEATH(APFloat(APFloat::IEEEdouble, "+0x0"), "Hex strings require an exponent");
1116 EXPECT_DEATH(APFloat(APFloat::IEEEdouble, "-0x0"), "Hex strings require an exponent");
1117
1118 EXPECT_DEATH(APFloat(APFloat::IEEEdouble, "0x0."), "Hex strings require an exponent");
1119 EXPECT_DEATH(APFloat(APFloat::IEEEdouble, "+0x0."), "Hex strings require an exponent");
1120 EXPECT_DEATH(APFloat(APFloat::IEEEdouble, "-0x0."), "Hex strings require an exponent");
1121
1122 EXPECT_DEATH(APFloat(APFloat::IEEEdouble, "0x.0"), "Hex strings require an exponent");
1123 EXPECT_DEATH(APFloat(APFloat::IEEEdouble, "+0x.0"), "Hex strings require an exponent");
1124 EXPECT_DEATH(APFloat(APFloat::IEEEdouble, "-0x.0"), "Hex strings require an exponent");
1125
1126 EXPECT_DEATH(APFloat(APFloat::IEEEdouble, "0x0.0"), "Hex strings require an exponent");
1127 EXPECT_DEATH(APFloat(APFloat::IEEEdouble, "+0x0.0"), "Hex strings require an exponent");
1128 EXPECT_DEATH(APFloat(APFloat::IEEEdouble, "-0x0.0"), "Hex strings require an exponent");
1129
1130 EXPECT_DEATH(APFloat(APFloat::IEEEdouble, StringRef("0x\0", 3)), "Invalid character in significand");
1131 EXPECT_DEATH(APFloat(APFloat::IEEEdouble, StringRef("0x1\0", 4)), "Invalid character in significand");
1132 EXPECT_DEATH(APFloat(APFloat::IEEEdouble, StringRef("0x1\02", 5)), "Invalid character in significand");
1133 EXPECT_DEATH(APFloat(APFloat::IEEEdouble, StringRef("0x1\02p1", 7)), "Invalid character in significand");
1134 EXPECT_DEATH(APFloat(APFloat::IEEEdouble, StringRef("0x1p\0", 5)), "Invalid character in exponent");
1135 EXPECT_DEATH(APFloat(APFloat::IEEEdouble, StringRef("0x1p1\0", 6)), "Invalid character in exponent");
1136 EXPECT_DEATH(APFloat(APFloat::IEEEdouble, StringRef("0x1p1\02", 7)), "Invalid character in exponent");
1137
1138 EXPECT_DEATH(APFloat(APFloat::IEEEdouble, "0x1p0f"), "Invalid character in exponent");
1139
1140 EXPECT_DEATH(APFloat(APFloat::IEEEdouble, "0x..p1"), "String contains multiple dots");
1141 EXPECT_DEATH(APFloat(APFloat::IEEEdouble, "0x..0p1"), "String contains multiple dots");
1142 EXPECT_DEATH(APFloat(APFloat::IEEEdouble, "0x1.0.0p1"), "String contains multiple dots");
1110 EXPECT_DEATH(APFloat(APFloat::IEEEdouble(), "0x"), "Invalid string");
1111 EXPECT_DEATH(APFloat(APFloat::IEEEdouble(), "+0x"), "Invalid string");
1112 EXPECT_DEATH(APFloat(APFloat::IEEEdouble(), "-0x"), "Invalid string");
1113
1114 EXPECT_DEATH(APFloat(APFloat::IEEEdouble(), "0x0"), "Hex strings require an exponent");
1115 EXPECT_DEATH(APFloat(APFloat::IEEEdouble(), "+0x0"), "Hex strings require an exponent");
1116 EXPECT_DEATH(APFloat(APFloat::IEEEdouble(), "-0x0"), "Hex strings require an exponent");
1117
1118 EXPECT_DEATH(APFloat(APFloat::IEEEdouble(), "0x0."), "Hex strings require an exponent");
1119 EXPECT_DEATH(APFloat(APFloat::IEEEdouble(), "+0x0."), "Hex strings require an exponent");
1120 EXPECT_DEATH(APFloat(APFloat::IEEEdouble(), "-0x0."), "Hex strings require an exponent");
1121
1122 EXPECT_DEATH(APFloat(APFloat::IEEEdouble(), "0x.0"), "Hex strings require an exponent");
1123 EXPECT_DEATH(APFloat(APFloat::IEEEdouble(), "+0x.0"), "Hex strings require an exponent");
1124 EXPECT_DEATH(APFloat(APFloat::IEEEdouble(), "-0x.0"), "Hex strings require an exponent");
1125
1126 EXPECT_DEATH(APFloat(APFloat::IEEEdouble(), "0x0.0"), "Hex strings require an exponent");
1127 EXPECT_DEATH(APFloat(APFloat::IEEEdouble(), "+0x0.0"), "Hex strings require an exponent");
1128 EXPECT_DEATH(APFloat(APFloat::IEEEdouble(), "-0x0.0"), "Hex strings require an exponent");
1129
1130 EXPECT_DEATH(APFloat(APFloat::IEEEdouble(), StringRef("0x\0", 3)), "Invalid character in significand");
1131 EXPECT_DEATH(APFloat(APFloat::IEEEdouble(), StringRef("0x1\0", 4)), "Invalid character in significand");
1132 EXPECT_DEATH(APFloat(APFloat::IEEEdouble(), StringRef("0x1\02", 5)), "Invalid character in significand");
1133 EXPECT_DEATH(APFloat(APFloat::IEEEdouble(), StringRef("0x1\02p1", 7)), "Invalid character in significand");
1134 EXPECT_DEATH(APFloat(APFloat::IEEEdouble(), StringRef("0x1p\0", 5)), "Invalid character in exponent");
1135 EXPECT_DEATH(APFloat(APFloat::IEEEdouble(), StringRef("0x1p1\0", 6)), "Invalid character in exponent");
1136 EXPECT_DEATH(APFloat(APFloat::IEEEdouble(), StringRef("0x1p1\02", 7)), "Invalid character in exponent");
1137
1138 EXPECT_DEATH(APFloat(APFloat::IEEEdouble(), "0x1p0f"), "Invalid character in exponent");
1139
1140 EXPECT_DEATH(APFloat(APFloat::IEEEdouble(), "0x..p1"), "String contains multiple dots");
1141 EXPECT_DEATH(APFloat(APFloat::IEEEdouble(), "0x..0p1"), "String contains multiple dots");
1142 EXPECT_DEATH(APFloat(APFloat::IEEEdouble(), "0x1.0.0p1"), "String contains multiple dots");
11431143 }
11441144
11451145 TEST(APFloatTest, StringHexadecimalSignificandDeath) {
1146 EXPECT_DEATH(APFloat(APFloat::IEEEdouble, "0x."), "Significand has no digits");
1147 EXPECT_DEATH(APFloat(APFloat::IEEEdouble, "+0x."), "Significand has no digits");
1148 EXPECT_DEATH(APFloat(APFloat::IEEEdouble, "-0x."), "Significand has no digits");
1149
1150 EXPECT_DEATH(APFloat(APFloat::IEEEdouble, "0xp"), "Significand has no digits");
1151 EXPECT_DEATH(APFloat(APFloat::IEEEdouble, "+0xp"), "Significand has no digits");
1152 EXPECT_DEATH(APFloat(APFloat::IEEEdouble, "-0xp"), "Significand has no digits");
1153
1154 EXPECT_DEATH(APFloat(APFloat::IEEEdouble, "0xp+"), "Significand has no digits");
1155 EXPECT_DEATH(APFloat(APFloat::IEEEdouble, "+0xp+"), "Significand has no digits");
1156 EXPECT_DEATH(APFloat(APFloat::IEEEdouble, "-0xp+"), "Significand has no digits");
1157
1158 EXPECT_DEATH(APFloat(APFloat::IEEEdouble, "0xp-"), "Significand has no digits");
1159 EXPECT_DEATH(APFloat(APFloat::IEEEdouble, "+0xp-"), "Significand has no digits");
1160 EXPECT_DEATH(APFloat(APFloat::IEEEdouble, "-0xp-"), "Significand has no digits");
1161
1162
1163 EXPECT_DEATH(APFloat(APFloat::IEEEdouble, "0x.p"), "Significand has no digits");
1164 EXPECT_DEATH(APFloat(APFloat::IEEEdouble, "+0x.p"), "Significand has no digits");
1165 EXPECT_DEATH(APFloat(APFloat::IEEEdouble, "-0x.p"), "Significand has no digits");
1166
1167 EXPECT_DEATH(APFloat(APFloat::IEEEdouble, "0x.p+"), "Significand has no digits");
1168 EXPECT_DEATH(APFloat(APFloat::IEEEdouble, "+0x.p+"), "Significand has no digits");
1169 EXPECT_DEATH(APFloat(APFloat::IEEEdouble, "-0x.p+"), "Significand has no digits");
1170
1171 EXPECT_DEATH(APFloat(APFloat::IEEEdouble, "0x.p-"), "Significand has no digits");
1172 EXPECT_DEATH(APFloat(APFloat::IEEEdouble, "+0x.p-"), "Significand has no digits");
1173 EXPECT_DEATH(APFloat(APFloat::IEEEdouble, "-0x.p-"), "Significand has no digits");
1146 EXPECT_DEATH(APFloat(APFloat::IEEEdouble(), "0x."), "Significand has no digits");
1147 EXPECT_DEATH(APFloat(APFloat::IEEEdouble(), "+0x."), "Significand has no digits");
1148 EXPECT_DEATH(APFloat(APFloat::IEEEdouble(), "-0x."), "Significand has no digits");
1149
1150 EXPECT_DEATH(APFloat(APFloat::IEEEdouble(), "0xp"), "Significand has no digits");
1151 EXPECT_DEATH(APFloat(APFloat::IEEEdouble(), "+0xp"), "Significand has no digits");
1152 EXPECT_DEATH(APFloat(APFloat::IEEEdouble(), "-0xp"), "Significand has no digits");
1153
1154 EXPECT_DEATH(APFloat(APFloat::IEEEdouble(), "0xp+"), "Significand has no digits");
1155 EXPECT_DEATH(APFloat(APFloat::IEEEdouble(), "+0xp+"), "Significand has no digits");
1156 EXPECT_DEATH(APFloat(APFloat::IEEEdouble(), "-0xp+"), "Significand has no digits");
1157
1158 EXPECT_DEATH(APFloat(APFloat::IEEEdouble(), "0xp-"), "Significand has no digits");
1159 EXPECT_DEATH(APFloat(APFloat::IEEEdouble(), "+0xp-"), "Significand has no digits");
1160 EXPECT_DEATH(APFloat(APFloat::IEEEdouble(), "-0xp-"), "Significand has no digits");
1161
1162
1163 EXPECT_DEATH(APFloat(APFloat::IEEEdouble(), "0x.p"), "Significand has no digits");
1164 EXPECT_DEATH(APFloat(APFloat::IEEEdouble(), "+0x.p"), "Significand has no digits");
1165 EXPECT_DEATH(APFloat(APFloat::IEEEdouble(), "-0x.p"), "Significand has no digits");
1166
1167 EXPECT_DEATH(APFloat(APFloat::IEEEdouble(), "0x.p+"), "Significand has no digits");
1168 EXPECT_DEATH(APFloat(APFloat::IEEEdouble(), "+0x.p+"), "Significand has no digits");
1169 EXPECT_DEATH(APFloat(APFloat::IEEEdouble(), "-0x.p+"), "Significand has no digits");
1170
1171 EXPECT_DEATH(APFloat(APFloat::IEEEdouble(), "0x.p-"), "Significand has no digits");
1172 EXPECT_DEATH(APFloat(APFloat::IEEEdouble(), "+0x.p-"), "Significand has no digits");
1173 EXPECT_DEATH(APFloat(APFloat::IEEEdouble(), "-0x.p-"), "Significand has no digits");
11741174 }
11751175
11761176 TEST(APFloatTest, StringHexadecimalExponentDeath) {
1177 EXPECT_DEATH(APFloat(APFloat::IEEEdouble, "0x1p"), "Exponent has no digits");
1178 EXPECT_DEATH(APFloat(APFloat::IEEEdouble, "+0x1p"), "Exponent has no digits");
1179 EXPECT_DEATH(APFloat(APFloat::IEEEdouble, "-0x1p"), "Exponent has no digits");
1180
1181 EXPECT_DEATH(APFloat(APFloat::IEEEdouble, "0x1p+"), "Exponent has no digits");
1182 EXPECT_DEATH(APFloat(APFloat::IEEEdouble, "+0x1p+"), "Exponent has no digits");
1183 EXPECT_DEATH(APFloat(APFloat::IEEEdouble, "-0x1p+"), "Exponent has no digits");
1184
1185 EXPECT_DEATH(APFloat(APFloat::IEEEdouble, "0x1p-"), "Exponent has no digits");
1186 EXPECT_DEATH(APFloat(APFloat::IEEEdouble, "+0x1p-"), "Exponent has no digits");
1187 EXPECT_DEATH(APFloat(APFloat::IEEEdouble, "-0x1p-"), "Exponent has no digits");
1188
1189
1190 EXPECT_DEATH(APFloat(APFloat::IEEEdouble, "0x1.p"), "Exponent has no digits");
1191 EXPECT_DEATH(APFloat(APFloat::IEEEdouble, "+0x1.p"), "Exponent has no digits");
1192 EXPECT_DEATH(APFloat(APFloat::IEEEdouble, "-0x1.p"), "Exponent has no digits");
1193
1194 EXPECT_DEATH(APFloat(APFloat::IEEEdouble, "0x1.p+"), "Exponent has no digits");
1195 EXPECT_DEATH(APFloat(APFloat::IEEEdouble, "+0x1.p+"), "Exponent has no digits");
1196 EXPECT_DEATH(APFloat(APFloat::IEEEdouble, "-0x1.p+"), "Exponent has no digits");
1197
1198 EXPECT_DEATH(APFloat(APFloat::IEEEdouble, "0x1.p-"), "Exponent has no digits");
1199 EXPECT_DEATH(APFloat(APFloat::IEEEdouble, "+0x1.p-"), "Exponent has no digits");
1200 EXPECT_DEATH(APFloat(APFloat::IEEEdouble, "-0x1.p-"), "Exponent has no digits");
1201
1202
1203 EXPECT_DEATH(APFloat(APFloat::IEEEdouble, "0x.1p"), "Exponent has no digits");
1204 EXPECT_DEATH(APFloat(APFloat::IEEEdouble, "+0x.1p"), "Exponent has no digits");
1205 EXPECT_DEATH(APFloat(APFloat::IEEEdouble, "-0x.1p"), "Exponent has no digits");
1206
1207 EXPECT_DEATH(APFloat(APFloat::IEEEdouble, "0x.1p+"), "Exponent has no digits");
1208 EXPECT_DEATH(APFloat(APFloat::IEEEdouble, "+0x.1p+"), "Exponent has no digits");
1209 EXPECT_DEATH(APFloat(APFloat::IEEEdouble, "-0x.1p+"), "Exponent has no digits");
1210
1211 EXPECT_DEATH(APFloat(APFloat::IEEEdouble, "0x.1p-"), "Exponent has no digits");
1212 EXPECT_DEATH(APFloat(APFloat::IEEEdouble, "+0x.1p-"), "Exponent has no digits");
1213 EXPECT_DEATH(APFloat(APFloat::IEEEdouble, "-0x.1p-"), "Exponent has no digits");
1214
1215
1216 EXPECT_DEATH(APFloat(APFloat::IEEEdouble, "0x1.1p"), "Exponent has no digits");
1217 EXPECT_DEATH(APFloat(APFloat::IEEEdouble, "+0x1.1p"), "Exponent has no digits");
1218 EXPECT_DEATH(APFloat(APFloat::IEEEdouble, "-0x1.1p"), "Exponent has no digits");
1219
1220 EXPECT_DEATH(APFloat(APFloat::IEEEdouble, "0x1.1p+"), "Exponent has no digits");
1221 EXPECT_DEATH(APFloat(APFloat::IEEEdouble, "+0x1.1p+"), "Exponent has no digits");
1222 EXPECT_DEATH(APFloat(APFloat::IEEEdouble, "-0x1.1p+"), "Exponent has no digits");
1223
1224 EXPECT_DEATH(APFloat(APFloat::IEEEdouble, "0x1.1p-"), "Exponent has no digits");
1225 EXPECT_DEATH(APFloat(APFloat::IEEEdouble, "+0x1.1p-"), "Exponent has no digits");
1226 EXPECT_DEATH(APFloat(APFloat::IEEEdouble, "-0x1.1p-"), "Exponent has no digits");
1177 EXPECT_DEATH(APFloat(APFloat::IEEEdouble(), "0x1p"), "Exponent has no digits");
1178 EXPECT_DEATH(APFloat(APFloat::IEEEdouble(), "+0x1p"), "Exponent has no digits");
1179 EXPECT_DEATH(APFloat(APFloat::IEEEdouble(), "-0x1p"), "Exponent has no digits");
1180
1181 EXPECT_DEATH(APFloat(APFloat::IEEEdouble(), "0x1p+"), "Exponent has no digits");
1182 EXPECT_DEATH(APFloat(APFloat::IEEEdouble(), "+0x1p+"), "Exponent has no digits");
1183 EXPECT_DEATH(APFloat(APFloat::IEEEdouble(), "-0x1p+"), "Exponent has no digits");
1184
1185 EXPECT_DEATH(APFloat(APFloat::IEEEdouble(), "0x1p-"), "Exponent has no digits");
1186 EXPECT_DEATH(APFloat(APFloat::IEEEdouble(), "+0x1p-"), "Exponent has no digits");
1187 EXPECT_DEATH(APFloat(APFloat::IEEEdouble(), "-0x1p-"), "Exponent has no digits");
1188
1189
1190 EXPECT_DEATH(APFloat(APFloat::IEEEdouble(), "0x1.p"), "Exponent has no digits");
1191 EXPECT_DEATH(APFloat(APFloat::IEEEdouble(), "+0x1.p"), "Exponent has no digits");
1192 EXPECT_DEATH(APFloat(APFloat::IEEEdouble(), "-0x1.p"), "Exponent has no digits");
1193
1194 EXPECT_DEATH(APFloat(APFloat::IEEEdouble(), "0x1.p+"), "Exponent has no digits");
1195 EXPECT_DEATH(APFloat(APFloat::IEEEdouble(), "+0x1.p+"), "Exponent has no digits");
1196 EXPECT_DEATH(APFloat(APFloat::IEEEdouble(), "-0x1.p+"), "Exponent has no digits");
1197
1198 EXPECT_DEATH(APFloat(APFloat::IEEEdouble(), "0x1.p-"), "Exponent has no digits");
1199 EXPECT_DEATH(APFloat(APFloat::IEEEdouble(), "+0x1.p-"), "Exponent has no digits");
1200 EXPECT_DEATH(APFloat(APFloat::IEEEdouble(), "-0x1.p-"), "Exponent has no digits");
1201
1202
1203 EXPECT_DEATH(APFloat(APFloat::IEEEdouble(), "0x.1p"), "Exponent has no digits");
1204 EXPECT_DEATH(APFloat(APFloat::IEEEdouble(), "+0x.1p"), "Exponent has no digits");
1205 EXPECT_DEATH(APFloat(APFloat::IEEEdouble(), "-0x.1p"), "Exponent has no digits");
1206
1207 EXPECT_DEATH(APFloat(APFloat::IEEEdouble(), "0x.1p+"), "Exponent has no digits");
1208 EXPECT_DEATH(APFloat(APFloat::IEEEdouble(), "+0x.1p+"), "Exponent has no digits");
1209 EXPECT_DEATH(APFloat(APFloat::IEEEdouble(), "-0x.1p+"), "Exponent has no digits");
1210
1211 EXPECT_DEATH(APFloat(APFloat::IEEEdouble(), "0x.1p-"), "Exponent has no digits");
1212 EXPECT_DEATH(APFloat(APFloat::IEEEdouble(), "+0x.1p-"), "Exponent has no digits");
1213 EXPECT_DEATH(APFloat(APFloat::IEEEdouble(), "-0x.1p-"), "Exponent has no digits");
1214
1215
1216 EXPECT_DEATH(APFloat(APFloat::IEEEdouble(), "0x1.1p"), "Exponent has no digits");
1217 EXPECT_DEATH(APFloat(APFloat::IEEEdouble(), "+0x1.1p"), "Exponent has no digits");
1218 EXPECT_DEATH(APFloat(APFloat::IEEEdouble(), "-0x1.1p"), "Exponent has no digits");
1219
1220 EXPECT_DEATH(APFloat(APFloat::IEEEdouble(), "0x1.1p+"), "Exponent has no digits");
1221 EXPECT_DEATH(APFloat(APFloat::IEEEdouble(), "+0x1.1p+"), "Exponent has no digits");
1222 EXPECT_DEATH(APFloat(APFloat::IEEEdouble(), "-0x1.1p+"), "Exponent has no digits");
1223
1224 EXPECT_DEATH(APFloat(APFloat::IEEEdouble(), "0x1.1p-"), "Exponent has no digits");
1225 EXPECT_DEATH(APFloat(APFloat::IEEEdouble(), "+0x1.1p-"), "Exponent has no digits");
1226 EXPECT_DEATH(APFloat(APFloat::IEEEdouble(), "-0x1.1p-"), "Exponent has no digits");
12271227 }
12281228 #endif
12291229 #endif
12361236 EXPECT_TRUE(inv.bitwiseIsEqual(APFloat(0.5)));
12371237 EXPECT_TRUE(APFloat(2.0f).getExactInverse(&inv));
12381238 EXPECT_TRUE(inv.bitwiseIsEqual(APFloat(0.5f)));
1239 EXPECT_TRUE(APFloat(APFloat::IEEEquad, "2.0").getExactInverse(&inv));
1240 EXPECT_TRUE(inv.bitwiseIsEqual(APFloat(APFloat::IEEEquad, "0.5")));
1241 EXPECT_TRUE(APFloat(APFloat::PPCDoubleDouble, "2.0").getExactInverse(&inv));
1242 EXPECT_TRUE(inv.bitwiseIsEqual(APFloat(APFloat::PPCDoubleDouble, "0.5")));
1243 EXPECT_TRUE(APFloat(APFloat::x87DoubleExtended, "2.0").getExactInverse(&inv));
1244 EXPECT_TRUE(inv.bitwiseIsEqual(APFloat(APFloat::x87DoubleExtended, "0.5")));
1239 EXPECT_TRUE(APFloat(APFloat::IEEEquad(), "2.0").getExactInverse(&inv));
1240 EXPECT_TRUE(inv.bitwiseIsEqual(APFloat(APFloat::IEEEquad(), "0.5")));
1241 EXPECT_TRUE(APFloat(APFloat::PPCDoubleDouble(), "2.0").getExactInverse(&inv));
1242 EXPECT_TRUE(inv.bitwiseIsEqual(APFloat(APFloat::PPCDoubleDouble(), "0.5")));
1243 EXPECT_TRUE(APFloat(APFloat::x87DoubleExtended(), "2.0").getExactInverse(&inv));
1244 EXPECT_TRUE(inv.bitwiseIsEqual(APFloat(APFloat::x87DoubleExtended(), "0.5")));
12451245
12461246 // FLT_MIN
12471247 EXPECT_TRUE(APFloat(1.17549435e-38f).getExactInverse(&inv));
12561256 }
12571257
12581258 TEST(APFloatTest, roundToIntegral) {
1259 APFloat T(-0.5), S(3.14), R(APFloat::getLargest(APFloat::IEEEdouble)), P(0.0);
1259 APFloat T(-0.5), S(3.14), R(APFloat::getLargest(APFloat::IEEEdouble())), P(0.0);
12601260
12611261 P = T;
12621262 P.roundToIntegral(APFloat::rmTowardZero);
12971297 P.roundToIntegral(APFloat::rmNearestTiesToEven);
12981298 EXPECT_EQ(R.convertToDouble(),