Skip to content

Commit f253786

Browse files
committed
Add check for C99 round function to configure, and define
a fallback function if round doesn't exist.
1 parent f498113 commit f253786

5 files changed

Lines changed: 24 additions & 3 deletions

File tree

Include/pymath.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ functions and constants
2222
extern double copysign(double, double);
2323
#endif
2424

25+
#ifndef HAVE_ROUND
26+
extern double round(double);
27+
#endif
28+
2529
#ifndef HAVE_ACOSH
2630
extern double acosh(double);
2731
#endif

Python/pymath.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,19 @@ copysign(double x, double y)
6969
}
7070
#endif /* HAVE_COPYSIGN */
7171

72+
#ifndef HAVE_ROUND
73+
double
74+
round(double x)
75+
{
76+
double absx, y;
77+
absx = fabs(x);
78+
y = floor(absx);
79+
if (absx - y >= 0.5)
80+
y += 1.0;
81+
return copysign(y, x);
82+
}
83+
#endif /* HAVE_ROUND */
84+
7285
#ifndef HAVE_LOG1P
7386
#include <float.h>
7487

configure

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#! /bin/sh
2-
# From configure.in Revision: 71274 .
2+
# From configure.in Revision: 71663 .
33
# Guess values for system-dependent variables and create Makefiles.
44
# Generated by GNU Autoconf 2.61 for python 3.1.
55
#
@@ -22310,7 +22310,8 @@ fi
2231022310

2231122311

2231222312

22313-
for ac_func in acosh asinh atanh copysign expm1 finite hypot log1p
22313+
22314+
for ac_func in acosh asinh atanh copysign expm1 finite hypot log1p round
2231422315
do
2231522316
as_ac_var=`echo "ac_cv_func_$ac_func" | $as_tr_sh`
2231622317
{ echo "$as_me:$LINENO: checking for $ac_func" >&5

configure.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3337,7 +3337,7 @@ then
33373337
[Define if tanh(-0.) is -0., or if platform doesn't have signed zeros])
33383338
fi
33393339

3340-
AC_CHECK_FUNCS([acosh asinh atanh copysign expm1 finite hypot log1p])
3340+
AC_CHECK_FUNCS([acosh asinh atanh copysign expm1 finite hypot log1p round])
33413341
AC_CHECK_DECLS([isinf, isnan, isfinite], [], [], [[#include <math.h>]])
33423342

33433343
LIBS=$LIBS_SAVE

pyconfig.h.in

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -521,6 +521,9 @@
521521
/* Define if you have readline 4.0 */
522522
#undef HAVE_RL_PRE_INPUT_HOOK
523523

524+
/* Define to 1 if you have the `round' function. */
525+
#undef HAVE_ROUND
526+
524527
/* Define to 1 if you have the `select' function. */
525528
#undef HAVE_SELECT
526529

0 commit comments

Comments
 (0)