Back to index

glibc  2.9
s_llrintf.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 __llrintf (float x)
00028 {
00029   int32_t e;
00030   u_int32_t i, s;
00031   long long int result;
00032 
00033   x = __m81_u(__rintf) (x);
00034 
00035   GET_FLOAT_WORD (i, x);
00036 
00037   e = ((i >> 23) & 0xff) - 0x7f;
00038   if (e < 0)
00039     return 0;
00040   s = i;
00041   i &= 0x7fffff;
00042   i |= 0x800000;
00043 
00044   if (e < 63)
00045     {
00046       if (e > 55)
00047        result = (long long int) (i << (e - 55)) << 32;
00048       else if (e > 31)
00049        result = (((long long int) (i >> (55 - e)) << 32) | (i << (e - 23)));
00050       else if (e > 23)
00051        result = i << (e - 23);
00052       else
00053        result = i >> (23 - e);
00054       if (s & 0x80000000)
00055        result = -result;
00056     }
00057   else
00058     /* The number is too large or not finite.  The standard leaves it
00059        undefined what to return when the number is too large to fit in a
00060        `long long int'.  */
00061     result = -1LL;
00062 
00063   return result;
00064 }
00065 
00066 weak_alias (__llrintf, llrintf)