summaryrefslogtreecommitdiffstats
path: root/Objects
diff options
context:
space:
mode:
authorMark Dickinson <mdickinson@enthought.com>2012-11-17 20:18:52 (GMT)
committerMark Dickinson <mdickinson@enthought.com>2012-11-17 20:18:52 (GMT)
commit115bc79df857a1b36db9b9d0df4d1a38cff97901 (patch)
tree4d95102c9e3b02ddcf1a8d32208be45bdee8e20f /Objects
parente3ae321222c32d64232c46e4062082effec79bcf (diff)
downloadcpython-115bc79df857a1b36db9b9d0df4d1a38cff97901.zip
cpython-115bc79df857a1b36db9b9d0df4d1a38cff97901.tar.gz
cpython-115bc79df857a1b36db9b9d0df4d1a38cff97901.tar.bz2
Issue #9742: Sneaky fix for build failure on Solaris 9.
Diffstat (limited to 'Objects')
-rw-r--r--Objects/floatobject.c9
1 files changed, 9 insertions, 0 deletions
diff --git a/Objects/floatobject.c b/Objects/floatobject.c
index 30f7b34..ba867ef 100644
--- a/Objects/floatobject.c
+++ b/Objects/floatobject.c
@@ -1088,6 +1088,15 @@ _Py_double_round(double x, int ndigits) {
PyObject *result = NULL;
_Py_SET_53BIT_PRECISION_HEADER;
+ /* Easy path for the common case ndigits == 0. */
+ if (ndigits == 0) {
+ rounded = round(x);
+ if (fabs(rounded - x) == 0.5)
+ /* halfway between two integers; use round-away-from-zero */
+ rounded = x + (x > 0.0 ? 0.5 : -0.5);
+ return PyFloat_FromDouble(rounded);
+ }
+
/* The basic idea is very simple: convert and round the double to a
decimal string using _Py_dg_dtoa, then convert that decimal string
back to a double with _Py_dg_strtod. There's one minor difficulty: