Add a static utility to FloatAttr for converting an APFloat to double.

--

PiperOrigin-RevId: 246671765
This commit is contained in:
River Riddle 2019-05-04 15:00:27 -07:00 committed by Mehdi Amini
parent 7fea30b9dd
commit 3f27c60688
2 changed files with 6 additions and 4 deletions

View File

@ -223,6 +223,7 @@ public:
/// This function is used to convert the value to a double, even if it loses
/// precision.
double getValueAsDouble() const;
static double getValueAsDouble(APFloat val);
/// Methods for support type inquiry through isa, cast, and dyn_cast.
static bool kindof(Kind kind) { return kind == Kind::Float; }

View File

@ -195,10 +195,11 @@ APFloat FloatAttr::getValue() const {
}
double FloatAttr::getValueAsDouble() const {
const auto &semantics = getType().cast<FloatType>().getFloatSemantics();
auto value = getValue();
bool losesInfo = false; // ignored
if (&semantics != &APFloat::IEEEdouble()) {
return getValueAsDouble(getValue());
}
double FloatAttr::getValueAsDouble(APFloat value) {
if (&value.getSemantics() != &APFloat::IEEEdouble()) {
bool losesInfo = false;
value.convert(APFloat::IEEEdouble(), APFloat::rmNearestTiesToEven,
&losesInfo);
}