Back to index

glibc  2.9
s_round.c
Go to the documentation of this file.
00001 /* Copyright (C) 2007 Free Software Foundation, Inc.
00002    This file is part of the GNU C Library.
00003 
00004    The GNU C Library is free software; you can redistribute it and/or
00005    modify it under the terms of the GNU Lesser General Public
00006    License as published by the Free Software Foundation; either
00007    version 2.1 of the License, or (at your option) any later version.
00008 
00009    The GNU C Library is distributed in the hope that it will be useful,
00010    but WITHOUT ANY WARRANTY; without even the implied warranty of
00011    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012    Lesser General Public License for more details.
00013 
00014    You should have received a copy of the GNU Lesser General Public
00015    License along with the GNU C Library; if not, write to the Free
00016    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
00017    02111-1307 USA.  */
00018 
00019 #include <math.h>
00020 #include <math_ldbl_opt.h>
00021 
00022 
00023 double
00024 __round (double x)
00025 {
00026   const double almost_half = 0x1.fffffffffffffp-2;
00027   const double two52 = 0x1.0p52;
00028   double tmp, r;
00029 
00030   __asm (
00031 #ifdef _IEEE_FP_INEXACT
00032         "addt/suic %2, %3, %1\n\tsubt/suic %1, %3, %0"
00033 #else
00034         "addt/suc %2, %3, %1\n\tsubt/suc %1, %3, %0"
00035 #endif
00036         : "=&f"(r), "=&f"(tmp)
00037         : "f"(fabs (x) + almost_half), "f"(two52));
00038 
00039   return copysign (r, x);
00040 }
00041 
00042 weak_alias (__round, round)
00043 #ifdef NO_LONG_DOUBLE
00044 strong_alias (__round, __roundl)
00045 weak_alias (__roundl, roundl)
00046 #endif
00047 #if LONG_DOUBLE_COMPAT(libm, GLIBC_2_1)
00048 compat_symbol (libm, __round, roundl, GLIBC_2_1);
00049 #endif