From 54d204073484a66315c6143cfbc9e67c3579fa7a Mon Sep 17 00:00:00 2001 From: Mike Frysinger Date: Sat, 8 Dec 2007 00:59:10 +0000 Subject: import trunc()/truncf() for ISO C requirements, otherwise fortran can hit infinite loops when it generates builtins+trunc() substitutes --- libm/Makefile.in | 4 ++-- libm/float_wrappers.c | 1 - libm/s_trunc.c | 58 +++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 60 insertions(+), 3 deletions(-) create mode 100644 libm/s_trunc.c (limited to 'libm') diff --git a/libm/Makefile.in b/libm/Makefile.in index 10869a88e..eb905e06a 100644 --- a/libm/Makefile.in +++ b/libm/Makefile.in @@ -68,8 +68,8 @@ libm_CSRC := \ s_ilogb.c s_ldexp.c s_lib_version.c s_lrint.c s_lround.c s_llround.c \ s_log1p.c s_logb.c s_matherr.c s_modf.c s_nextafter.c s_round.c \ s_rint.c s_scalbn.c s_signgam.c s_significand.c s_sin.c s_tan.c \ - s_tanh.c w_acos.c w_acosh.c w_asin.c w_atan2.c w_atanh.c w_cabs.c \ - w_cosh.c w_drem.c w_exp.c w_fmod.c w_gamma.c w_gamma_r.c \ + s_tanh.c s_trunc.c w_acos.c w_acosh.c w_asin.c w_atan2.c w_atanh.c \ + w_cabs.c w_cosh.c w_drem.c w_exp.c w_fmod.c w_gamma.c w_gamma_r.c \ w_hypot.c w_j0.c w_j1.c w_jn.c w_lgamma.c w_lgamma_r.c \ w_log.c w_log10.c w_pow.c w_remainder.c w_scalb.c w_sinh.c \ w_sqrt.c fpmacros.c nan.c carg.c s_llrint.c diff --git a/libm/float_wrappers.c b/libm/float_wrappers.c index cd841e661..cd0ae1832 100644 --- a/libm/float_wrappers.c +++ b/libm/float_wrappers.c @@ -26,7 +26,6 @@ #undef L_remquof /*float remquof(float, float, int *);*/ #undef L_scalblnf /*float scalblnf(float, long);*/ #undef L_tgammaf /*float tgammaf(float);*/ -#undef L_truncf /*float truncf(float);*/ /* Implement the following, as defined by SuSv3 */ #if 0 diff --git a/libm/s_trunc.c b/libm/s_trunc.c new file mode 100644 index 000000000..8a4f5ae05 --- /dev/null +++ b/libm/s_trunc.c @@ -0,0 +1,58 @@ +/* Truncate argument to nearest integral value not larger than the argument. + Copyright (C) 1997, 1998 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by Ulrich Drepper , 1997. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + 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. */ + +#include + +#include "math_private.h" + + +libm_hidden_proto(trunc) +double +trunc (double x) +{ + int32_t i0, j0; + u_int32_t i1; + int sx; + + EXTRACT_WORDS (i0, i1, x); + sx = i0 & 0x80000000; + j0 = ((i0 >> 20) & 0x7ff) - 0x3ff; + if (j0 < 20) + { + if (j0 < 0) + /* The magnitude of the number is < 1 so the result is +-0. */ + INSERT_WORDS (x, sx, 0); + else + INSERT_WORDS (x, sx | (i0 & ~(0x000fffff >> j0)), 0); + } + else if (j0 > 51) + { + if (j0 == 0x400) + /* x is inf or NaN. */ + return x + x; + } + else + { + INSERT_WORDS (x, i0, i1 & ~(0xffffffffu >> (j0 - 20))); + } + + return x; +} +libm_hidden_def(trunc) -- cgit v1.2.3