]> git.ipfire.org Git - thirdparty/gcc.git/blobdiff - libquadmath/math/lroundq.c
Update most of libquadmath/math/ from glibc, automate update (PR libquadmath/68686).
[thirdparty/gcc.git] / libquadmath / math / lroundq.c
index 55285034cec61c7c7c7771a8beb31c5c49d5a860..0ce4ce0c1bcb4df25f32997d199f869afb689cf5 100644 (file)
@@ -1,5 +1,5 @@
-/* Round __float128 value to long int.
-   Copyright (C) 1997-2017 Free Software Foundation, Inc.
+/* Round long double value to long int.
+   Copyright (C) 1997-2018 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
    Contributed by Ulrich Drepper <drepper@cygnus.com>, 1997 and
                  Jakub Jelinek <jj@ultra.linux.cz>, 1999.
    Lesser General Public License for more details.
 
    You should have received a copy of the GNU Lesser General Public
-   License along with the GNU C Library; if not, write to the Free
-   Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
-   02111-1307 USA.  */
+   License along with the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
 
 #include "quadmath-imp.h"
 
-
 long int
 lroundq (__float128 x)
 {
@@ -46,7 +44,7 @@ lroundq (__float128 x)
            {
              i0 += 0x0000800000000000LL >> j0;
              result = i0 >> (48 - j0);
-#if defined FE_INVALID && defined USE_FENV_H
+#ifdef FE_INVALID
              if (sizeof (long int) == 4
                  && sign == 1
                  && result == LONG_MIN)
@@ -68,7 +66,7 @@ lroundq (__float128 x)
          else
            {
              result = ((long int) i0 << (j0 - 48)) | (j >> (112 - j0));
-#if defined FE_INVALID && defined USE_FENV_H
+#ifdef FE_INVALID
              if (sizeof (long int) == 8
                  && sign == 1
                  && result == LONG_MIN)
@@ -84,16 +82,23 @@ lroundq (__float128 x)
         FE_INVALID must be raised and the return value is
         unspecified.  */
 #ifdef FE_INVALID
-      if (x <= (__float128) LONG_MIN - 0.5Q)
+      if (FIX_FLT128_LONG_CONVERT_OVERFLOW
+         && !(sign == -1 && x > (__float128) LONG_MIN - 0.5Q))
+       {
+         feraiseexcept (FE_INVALID);
+         return sign == 1 ? LONG_MAX : LONG_MIN;
+       }
+      else if (!FIX_FLT128_LONG_CONVERT_OVERFLOW
+              && x <= (__float128) LONG_MIN - 0.5Q)
        {
          /* If truncation produces LONG_MIN, the cast will not raise
             the exception, but may raise "inexact".  */
-#ifdef USE_FENV_H
          feraiseexcept (FE_INVALID);
-#endif
          return LONG_MIN;
        }
 #endif
+      /* The number is too large.  It is left implementation defined
+        what happens.  */
       return (long int) x;
     }