[llvm-commits] [llvm] r47738 - in /llvm/trunk: include/llvm/ADT/APFloat.h lib/Support/APFloat.cpp

Dan Gohman gohman at apple.com
Thu Feb 28 17:26:13 PST 2008


Author: djg
Date: Thu Feb 28 19:26:11 2008
New Revision: 47738

URL: http://llvm.org/viewvc/llvm-project?rev=47738&view=rev
Log:
Add a method to APFloat to convert directly from APInt.

Modified:
    llvm/trunk/include/llvm/ADT/APFloat.h
    llvm/trunk/lib/Support/APFloat.cpp

Modified: llvm/trunk/include/llvm/ADT/APFloat.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ADT/APFloat.h?rev=47738&r1=47737&r2=47738&view=diff

==============================================================================
--- llvm/trunk/include/llvm/ADT/APFloat.h (original)
+++ llvm/trunk/include/llvm/ADT/APFloat.h Thu Feb 28 19:26:11 2008
@@ -208,6 +208,8 @@
     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,

Modified: llvm/trunk/lib/Support/APFloat.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/APFloat.cpp?rev=47738&r1=47737&r2=47738&view=diff

==============================================================================
--- llvm/trunk/lib/Support/APFloat.cpp (original)
+++ llvm/trunk/lib/Support/APFloat.cpp Thu Feb 28 19:26:11 2008
@@ -1913,6 +1913,23 @@
   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.  */





More information about the llvm-commits mailing list