Add an abs() function to get the absolute value.
authorReid Spencer <rspencer@reidspencer.com>
Thu, 1 Mar 2007 23:37:09 +0000 (23:37 +0000)
committerReid Spencer <rspencer@reidspencer.com>
Thu, 1 Mar 2007 23:37:09 +0000 (23:37 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@34819 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/ADT/APInt.h

index 15652a2b71b868f2a1b11cc8998c317c0c7f4844..07e22fc9828dd6bd696537c3827dcdbc039f08a9 100644 (file)
@@ -759,6 +759,14 @@ public:
 
   /// @brief Compute the square root
   APInt sqrt() const;
+
+  /// If *this is < 0 then return -(*this), otherwise *this;
+  /// @brief Get the absolute value;
+  APInt abs() const {
+    if (isNegative())
+      return -(*this);
+    return *this;
+  }
 };
 
 inline bool operator==(uint64_t V1, const APInt& V2) {