summaryrefslogtreecommitdiff
path: root/numpy
diff options
context:
space:
mode:
authorCharles Harris <charlesr.harris@gmail.com>2013-01-20 17:04:31 -0800
committerCharles Harris <charlesr.harris@gmail.com>2013-01-20 17:04:31 -0800
commite548eedba12831bd5d68cb9c52a86e9330aa8ae0 (patch)
tree993137ac4786a69e8e56a7d6dd2396f16d57c71f /numpy
parent56b06fe5bf20d11ca8188a00333ddf69ed8b2e42 (diff)
parentd55b5aa49d2ba1c98d568660b1a91b4b552872f0 (diff)
downloadnumpy-e548eedba12831bd5d68cb9c52a86e9330aa8ae0.tar.gz
Merge pull request #2936 from charris/fix-print-negative-float-zero
Fix print negative float zero
Diffstat (limited to 'numpy')
-rw-r--r--numpy/core/src/multiarray/scalartypes.c.src2
-rw-r--r--numpy/core/tests/test_scalarprint.py29
2 files changed, 30 insertions, 1 deletions
diff --git a/numpy/core/src/multiarray/scalartypes.c.src b/numpy/core/src/multiarray/scalartypes.c.src
index dacb9c9ce..52d59f43a 100644
--- a/numpy/core/src/multiarray/scalartypes.c.src
+++ b/numpy/core/src/multiarray/scalartypes.c.src
@@ -468,7 +468,7 @@ format_@name@(char *buf, size_t buflen, @type@ val, unsigned int prec)
/* If nothing but digits after sign, append ".0" */
cnt = strlen(buf);
- for (i = (val < 0) ? 1 : 0; i < cnt; ++i) {
+ for (i = (buf[0] == '-') ? 1 : 0; i < cnt; ++i) {
if (!isdigit(Py_CHARMASK(buf[i]))) {
break;
}
diff --git a/numpy/core/tests/test_scalarprint.py b/numpy/core/tests/test_scalarprint.py
new file mode 100644
index 000000000..3bed7e62a
--- /dev/null
+++ b/numpy/core/tests/test_scalarprint.py
@@ -0,0 +1,29 @@
+# -*- coding: utf-8 -*-
+""" Test printing of scalar types.
+
+"""
+
+import numpy as np
+from numpy.testing import TestCase, assert_, run_module_suite
+
+
+class TestRealScalars(TestCase):
+ def test_str(self):
+ svals = [0.0, -0.0, 1, -1, np.inf, -np.inf, np.nan]
+ styps = [np.float16, np.float32, np.float64, np.longdouble]
+ actual = [str(f(c)) for c in svals for f in styps]
+ wanted = [
+ '0.0', '0.0', '0.0', '0.0',
+ '-0.0', '-0.0', '-0.0', '-0.0',
+ '1.0', '1.0', '1.0', '1.0',
+ '-1.0', '-1.0', '-1.0', '-1.0',
+ 'inf', 'inf', 'inf', 'inf',
+ '-inf', '-inf', '-inf', '-inf',
+ 'nan', 'nan', 'nan', 'nan']
+
+ for res, val in zip(actual, wanted):
+ assert_(res == val)
+
+
+if __name__ == "__main__":
+ run_module_suite()