From 4c297c9153899a41c541474187a3e3a8dbf8a794 Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Sat, 15 May 2010 17:11:55 +0000 Subject: [PATCH] improve portability to systems that don't have round, patch by Evzen Muller! git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@103877 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/Config/config.h.cmake | 3 +++ lib/Support/APInt.cpp | 7 +++---- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/include/llvm/Config/config.h.cmake b/include/llvm/Config/config.h.cmake index adbcc1132fb..e7594babaa6 100644 --- a/include/llvm/Config/config.h.cmake +++ b/include/llvm/Config/config.h.cmake @@ -312,6 +312,9 @@ /* Define to 1 if you have the `roundf' function. */ #undef HAVE_ROUNDF +/* Define to 1 if you have the `round' function. */ +#cmakedefine HAVE_ROUND ${HAVE_ROUND} + /* Define to 1 if you have the `sbrk' function. */ #cmakedefine HAVE_SBRK ${HAVE_SBRK} diff --git a/lib/Support/APInt.cpp b/lib/Support/APInt.cpp index 50025d214bc..1341d214370 100644 --- a/lib/Support/APInt.cpp +++ b/lib/Support/APInt.cpp @@ -1382,13 +1382,12 @@ APInt APInt::sqrt() const { // libc sqrt function which will probably use a hardware sqrt computation. // This should be faster than the algorithm below. if (magnitude < 52) { -#if defined( _MSC_VER ) || defined(_MINIX) - // Amazingly, VC++ and Minix don't have round(). +#if HAVE_ROUND return APInt(BitWidth, - uint64_t(::sqrt(double(isSingleWord()?VAL:pVal[0]))) + 0.5); + uint64_t(::round(::sqrt(double(isSingleWord()?VAL:pVal[0]))))); #else return APInt(BitWidth, - uint64_t(::round(::sqrt(double(isSingleWord()?VAL:pVal[0]))))); + uint64_t(::sqrt(double(isSingleWord()?VAL:pVal[0]))) + 0.5); #endif } -- 2.11.0