diff options
author | Reid Spencer <rspencer@reidspencer.com> | 2007-03-01 23:37:09 +0000 |
---|---|---|
committer | Reid Spencer <rspencer@reidspencer.com> | 2007-03-01 23:37:09 +0000 |
commit | b45a221348ee8693f1bff2df7b42689497083d41 (patch) | |
tree | 139b28fd5a59cdd73b557057b0c75d123a9264fa | |
parent | 295e40aa5ca771c2841d30332d7b4266fb306d6f (diff) |
Add an abs() function to get the absolute value.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@34819 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | include/llvm/ADT/APInt.h | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/include/llvm/ADT/APInt.h b/include/llvm/ADT/APInt.h index 15652a2b71..07e22fc982 100644 --- a/include/llvm/ADT/APInt.h +++ b/include/llvm/ADT/APInt.h @@ -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) { |