forked from OSchip/llvm-project
Add a static utility to FloatAttr for converting an APFloat to double.
-- PiperOrigin-RevId: 246671765
This commit is contained in:
parent
7fea30b9dd
commit
3f27c60688
|
@ -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; }
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue