Back to index

glibc  2.9
s_llrintl.c
Go to the documentation of this file.
00001 /* Round argument to nearest integral value according to current rounding
00002    direction.
00003    Copyright (C) 1997, 1999 Free Software Foundation, Inc.
00004    This file is part of the GNU C Library.
00005    Contributed by Andreas Schwab <schwab@issan.informatik.uni-dortmund.de>
00006 
00007    The GNU C Library is free software; you can redistribute it and/or
00008    modify it under the terms of the GNU Lesser General Public
00009    License as published by the Free Software Foundation; either
00010    version 2.1 of the License, or (at your option) any later version.
00011 
00012    The GNU C Library is distributed in the hope that it will be useful,
00013    but WITHOUT ANY WARRANTY; without even the implied warranty of
00014    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015    Lesser General Public License for more details.
00016 
00017    You should have received a copy of the GNU Lesser General Public
00018    License along with the GNU C Library; if not, write to the Free
00019    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
00020    02111-1307 USA.  */
00021 
00022 #include <math.h>
00023 #include "math_private.h"
00024 #include "mathimpl.h"
00025 
00026 long long int
00027 __llrintl (long double x)
00028 {
00029   int32_t e, s;
00030   u_int32_t h, l;
00031   long long int result;
00032 
00033   x = __m81_u(__rintl) (x);
00034 
00035   GET_LDOUBLE_WORDS (e, h, l, x);
00036 
00037   s = e;
00038   e = (e & 0x7fff) - 0x3fff;
00039   if (e < 0)
00040     return 0;
00041 
00042   if (e < 63)
00043     {
00044       if (e > 31)
00045        {
00046          l >>= 63 - e;
00047          l |= h << (e - 31);
00048          h >>= 63 - e;
00049          result = ((long long int) h << 32) | l;
00050        }
00051       else
00052        result = h >> (31 - e);
00053       if (s & 0x8000)
00054        result = -result;
00055     }
00056   else
00057     /* The number is too large or not finite.  The standard leaves it
00058        undefined what to return when the number is too large to fit in a
00059        `long long int'.  */
00060     result = -1LL;
00061 
00062   return result;
00063 }
00064 
00065 weak_alias (__llrintl, llrintl)