Add a method to APFloat to convert directly from APInt.
authorDan Gohman <gohman@apple.com>
Fri, 29 Feb 2008 01:26:11 +0000 (01:26 +0000)
committerDan Gohman <gohman@apple.com>
Fri, 29 Feb 2008 01:26:11 +0000 (01:26 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@47738 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/ADT/APFloat.h
lib/Support/APFloat.cpp

index 65cb1e56bb859518a2df29f9a06e9dd50d69f07e..411d8add25f6f2e686603303a41c2f26c55d7e33 100644 (file)
@@ -208,6 +208,8 @@ namespace llvm {
     opStatus convert(const fltSemantics &, roundingMode);
     opStatus convertToInteger(integerPart *, unsigned int, bool,
                               roundingMode) const;
+    opStatus convertFromAPInt(const APInt &,
+                              bool, roundingMode);
     opStatus convertFromSignExtendedInteger(const integerPart *, unsigned int,
                                             bool, roundingMode);
     opStatus convertFromZeroExtendedInteger(const integerPart *, unsigned int,
index cc86e795e7927e6616b05b0441bd3a66f062a099..3b448208842633111d1512ef0989295f31a03d04 100644 (file)
@@ -1913,6 +1913,23 @@ APFloat::convertFromUnsignedParts(const integerPart *src,
   return normalize(rounding_mode, lost_fraction);
 }
 
+APFloat::opStatus
+APFloat::convertFromAPInt(const APInt &Val,
+                          bool isSigned,
+                          roundingMode rounding_mode)
+{
+  unsigned int partCount = Val.getNumWords();
+  APInt api = Val;
+
+  sign = false;
+  if (isSigned && api.isNegative()) {
+    sign = true;
+    api = -api;
+  }
+
+  return convertFromUnsignedParts(api.getRawData(), partCount, rounding_mode);
+}
+
 /* Convert a two's complement integer SRC to a floating point number,
    rounding according to ROUNDING_MODE.  ISSIGNED is true if the
    integer is signed, in which case it must be sign-extended.  */