forked from OSchip/llvm-project
[APFloat] Added support for parsing float strings which contain {inf,-inf,NaN,-NaN}.
llvm-svn: 184713
This commit is contained in:
parent
c4facdf390
commit
40e8a187f6
|
@ -510,6 +510,7 @@ private:
|
|||
/// \name Miscellany
|
||||
/// @{
|
||||
|
||||
bool convertFromStringSpecials(StringRef str);
|
||||
opStatus normalize(roundingMode, lostFraction);
|
||||
opStatus addOrSubtract(const APFloat &, roundingMode, bool subtract);
|
||||
cmpResult compareAbsoluteValue(const APFloat &) const;
|
||||
|
|
|
@ -2575,11 +2575,40 @@ APFloat::convertFromDecimalString(StringRef str, roundingMode rounding_mode)
|
|||
return fs;
|
||||
}
|
||||
|
||||
bool
|
||||
APFloat::convertFromStringSpecials(StringRef str) {
|
||||
if (str.equals("inf") || str.equals("INFINITY")) {
|
||||
makeInf(false);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (str.equals("-inf") || str.equals("-INFINITY")) {
|
||||
makeInf(true);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (str.equals("nan") || str.equals("NaN")) {
|
||||
makeNaN(false, false);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (str.equals("-nan") || str.equals("-NaN")) {
|
||||
makeNaN(false, true);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
APFloat::opStatus
|
||||
APFloat::convertFromString(StringRef str, roundingMode rounding_mode)
|
||||
{
|
||||
assert(!str.empty() && "Invalid string length");
|
||||
|
||||
// Handle special cases.
|
||||
if (convertFromStringSpecials(str))
|
||||
return opOK;
|
||||
|
||||
/* Handle a leading minus sign. */
|
||||
StringRef::iterator p = str.begin();
|
||||
size_t slen = str.size();
|
||||
|
|
Loading…
Reference in New Issue