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 | 76b2ce19fc0c6eaedb46dc9bfab3f361fd0c80f9 (patch) | |
| tree | bde859c6c7f57d9d041c95650d52d8c5f942b994 | |
| parent | 1b8dfcbaaa6a0eae28b94d29cd71e6463d6304d5 (diff) | |
| download | bcm5719-llvm-76b2ce19fc0c6eaedb46dc9bfab3f361fd0c80f9.tar.gz bcm5719-llvm-76b2ce19fc0c6eaedb46dc9bfab3f361fd0c80f9.zip | |
Add an abs() function to get the absolute value.
llvm-svn: 34819
| -rw-r--r-- | llvm/include/llvm/ADT/APInt.h | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/llvm/include/llvm/ADT/APInt.h b/llvm/include/llvm/ADT/APInt.h index 15652a2b71b..07e22fc9828 100644 --- a/llvm/include/llvm/ADT/APInt.h +++ b/llvm/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) { |

