[gfortran] patch for PR 15292 missing round and roundf

Bud Davis bdavis9659@comcast.net
Sat Jun 12 18:24:00 GMT 2004


adds steve kargl's implmentation of these two functions along with a
configure test.

i expect we will have a few more of these, thus the name
"c99_functions.c".


--bud



Change Log:

2004  Bud Davis  <bdavis9659@comcast.net>
      Steve Kargl  <sgk@troutmask.apl.washington.edu>

	PR gfortran/15292
	* intrinsics/c99_functions.c: New file.
	* Makefile.am: Add new file.
	* configure.ac: Added test for round/roundf.
	* Makefile.in: Regenerate.
	* configure: Regenerate.
        * configure.h.in: Regenerate.

 
Index: gcc/libgfortran/Makefile.am
===================================================================
RCS file: /cvs/gcc/gcc/libgfortran/Makefile.am,v
retrieving revision 1.7
diff -c -3 -n -p -r1.7 Makefile.am
*** gcc/libgfortran/Makefile.am	12 Jun 2004 13:42:45 -0000	1.7
--- gcc/libgfortran/Makefile.am	12 Jun 2004 15:31:11 -0000
*************** gfor_helper_src= \
*** 37,42 ****
--- 37,43 ----
  intrinsics/associated.c \
  intrinsics/abort.c \
  intrinsics/args.c \
+ intrinsics/c99_functions.c \
  intrinsics/cpu_time.c \
  intrinsics/cshift0.c \
  intrinsics/eoshift0.c \
Index: gcc/libgfortran/configure.ac
===================================================================
RCS file: /cvs/gcc/gcc/libgfortran/configure.ac,v
retrieving revision 1.1
diff -c -3 -n -p -r1.1 configure.ac
*** gcc/libgfortran/configure.ac	30 May 2004 21:58:10 -0000	1.1
--- gcc/libgfortran/configure.ac	12 Jun 2004 15:31:14 -0000
*************** AC_CHECK_LIB([mx],[csin],[need_math="no"
*** 166,171 ****
--- 166,175 ----
  # Check for library functions.
  AC_CHECK_FUNCS(getrusage times)
  
+ # Check for some C99 functions
+ AC_CHECK_LIB([m],[round],[AC_DEFINE([HAVE_ROUND],[1],["c99 function"])])
+ AC_CHECK_LIB([m],[roundf],[AC_DEFINE([HAVE_ROUNDF],[1],["c99 function"])])
+ 
  # Let the user override this
  AC_ARG_ENABLE(cmath,
  	AC_HELP_STRING([--enable-cmath],[Include complex math functions]),


and the file:

/* Implementation of various C99 functions 
   Copyright (C) 2004 Free Software Foundation, Inc.

This file is part of the GNU Fortran 95 runtime library (libgfortran).

Libgfortran 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.

Libgfortran 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 libgfortran; see the file COPYING.LIB.  If not,
write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.  */

#include "config.h"
#include <sys/types.h>
#include <math.h>
#include "libgfortran.h"


/* algorithm by Steven G. Kargl */

#ifndef HAVE_ROUND
/* round(x)
 * round to nearest integral value.  If the argument is halfway between two
 * integral values then round away from zero.
 */

double
round(double x)
{
   double t;
   int i;

   i = fpclassify(x);
   if (i == FP_INFINITE || i == FP_NAN)
     return (x);

   if (x >= 0.0) 
    {
      t = ceil(x);
      if (t - x > 0.5)
        t -= 1.0;
      return (t);
    } 
   else 
    {
      t = ceil(-x);
      if (t + x > 0.5)
        t -= 1.0;
      return (-t);
    }
}
#endif

#ifndef HAVE_ROUNDF
/* roundf(x)
 * Round to nearest integral value.  If the argument is halfway between two
 * integral values then round away from zero.
 */

float
roundf(float x)
{
   float t;
   int i;

   i = fpclassify(x);
   if (i == FP_INFINITE || i == FP_NAN)
     return (x);

   if (x >= 0.0) 
    {
      t = ceilf(x);
      if (t - x > 0.5)
        t -= 1.0;
      return (t);
    } 
   else 
    {
      t = ceilf(-x);
      if (t + x > 0.5)
        t -= 1.0;
      return (-t);
    }
}
#endif




More information about the Gcc-patches mailing list