8000 Merge pull request #11104 from ahaldane/fixup_hack_double_double_1.14.4 · r-devulap/numpy@64e4a07 · GitHub
[go: up one dir, main page]

Skip to content

Commit 64e4a07

Browse files
authored
Merge pull request numpy#11104 from ahaldane/fixup_hack_double_double_1.14.4
BUG: str of DOUBLE_DOUBLE format wrong on ppc64
2 parents 6c4caa0 + 0f88930 commit 64e4a07

File tree

2 files changed

+61
-8
lines changed

2 files changed

+61
-8
lines changed

doc/release/1.14.4-notes.rst

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
==========================
2+
NumPy 1.14.4 Release Notes
3+
==========================
4+
5+
This is a bugfix release for bugs reported following the 1.14.3 release:
6+
7+
* float128 values on ppc systems now print more correctly. The whitespace
8+
padding is still incorrect and is to be fixed in numpy 1.15. Numpy still
9+
fails some printing-related (and other) unit tests on ppc systems.
10+
* float values printed in the python2 interactive shell had extra quote marks
11+
12+
The Python versions supported in this release are 2.7 and 3.4 - 3.6. The Python
13+
3.6 wheels available from PIP are built with Python 3.6.2 and should be
14+
compatible with all previous versions of Python 3.6. The source releases were
15+
cythonized with Cython 0.28.2.
16+
17+
Contributors
18+
============

numpy/core/src/multiarray/dragon4.c

Lines changed: 43 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2404,6 +2404,8 @@ Dragon4_PrintFloat64(char *buffer, npy_uint32 bufferSize, npy_float64 value,
24042404
}
24052405
}
24062406

2407+
#if !(defined(HAVE_LDOUBLE_DOUBLE_DOUBLE_BE) || \
2408+
defined(HAVE_LDOUBLE_DOUBLE_DOUBLE_LE))
24072409
static npy_uint32
24082410
Dragon4_PrintFloat128(char *buffer, npy_uint32 bufferSize, FloatVal128 value,
24092411
npy_bool scientific, DigitMode digit_mode,
@@ -2499,6 +2501,7 @@ Dragon4_PrintFloat128(char *buffer, npy_uint32 bufferSize, FloatVal128 value,
24992501
digits_left, digits_right);
25002502
}
25012503
}
2504+
#endif /* DOUBLE_DOUBLE */
25022505

25032506
PyObject *
25042507
Dragon4_Positional_AnySize(void *val, size_t size, DigitMode digit_mode,
@@ -2510,16 +2513,22 @@ Dragon4_Positional_AnySize(void *val, size_t size, DigitMode digit_mode,
25102513
* 16384 should be enough to uniquely print any float128, which goes up
25112514
* to about 10^4932 */
25122515
static char repr[16384];
2516+
#if !(defined(HAVE_LDOUBLE_DOUBLE_DOUBLE_BE) || \
2517+
defined(HAVE_LDOUBLE_DOUBLE_DOUBLE_LE))
25132518
FloatVal128 val128;
2519+
#ifdef NPY_FLOAT128
2520+
FloatUnion128 buf128;
2521+
#endif
2522+
#else /* DOUBLE_DOUBLE */
2523+
PyObject *out, *ret;
2524+
#endif /* DOUBLE_DOUBLE */
2525+
25142526
#ifdef NPY_FLOAT80
25152527
FloatUnion80 buf80;;
25162528
#endif
25172529
#ifdef NPY_FLOAT96
25182530
FloatUnion96 buf96;
25192531
#endif
2520-
#ifdef NPY_FLOAT128
2521-
FloatUnion128 buf128;
2522-
#endif
25232532

25242533
switch (size) {
25252534
case 2:
@@ -2559,14 +2568,29 @@ Dragon4_Positional_AnySize(void *val, size_t size, DigitMode digit_mode,
25592568
#endif
25602569
#ifdef NPY_FLOAT128
25612570
case 16:
2571+
/* Numpy 1.14 does not support the DOUBLE_DOUBLE format properly */
2572+
#if defined(HAVE_LDOUBLE_DOUBLE_DOUBLE_BE) || \
2573+
defined(HAVE_LDOUBLE_DOUBLE_DOUBLE_LE)
2574+
PyOS_snprintf(repr, sizeof(repr), "%.*Lf", precision,
2575+
*(npy_float128*)val);
2576+
out = PyUString_FromString(repr);
2577+
if (out == NULL) {
2578+
return out;
2579+
}
2580+
/* strip trailing zeros to roughly emulate normal behavior */
2581+
ret = PyObject_CallMethod(out, "rstrip", "s", "0");
2582+
Py_DECREF(out);
2583+
return ret;
2584+
#else
25622585
buf128.floatingPoint = *(npy_float128*)val;
25632586
val128.integer[0] = buf128.integer.a;
25642587
val128.integer[1] = buf128.integer.b;
25652588
Dragon4_PrintFloat128(repr, sizeof(repr), val128,
25662589
0, digit_mode, cutoff_mode, precision,
25672590
sign, trim, pad_left, pad_right, -1);
2591+
#endif /* DOUBLE_DOUBLE */
25682592
break;
2569-
#endif
2593+
#endif /* NPY_FLOAT128 */
25702594
default:
25712595
PyErr_Format(PyExc_ValueError, "unexpected itemsize %zu", size);
25722596
return NULL;
@@ -2623,16 +2647,20 @@ Dragon4_Scientific_AnySize(void *val, size_t size, DigitMode digit_mode,
26232647
{
26242648
/* use a very large buffer in case anyone tries to output a large precision */
26252649
static char repr[4096];
2650+
#if !(defined(HAVE_LDOUBLE_DOUBLE_DOUBLE_BE) || \
2651+
defined(HAVE_LDOUBLE_DOUBLE_DOUBLE_LE))
26262652
FloatVal128 val128;
2653+
#ifdef NPY_FLOAT128
2654+
FloatUnion128 buf128;
2655+
#endif
2656+
#endif /* DOUBLE_DOUBLE */
2657+
26272658
#ifdef NPY_FLOAT80
26282659
FloatUnion80 buf80;;
26292660
#endif
26302661
#ifdef NPY_FLOAT96
26312662
FloatUnion96 buf96;
26322663
#endif
2633-
#ifdef NPY_FLOAT128
2634-
FloatUnion128 buf128;
2635-
#endif
26362664

26372665
/* dummy, is ignored in scientific mode */
26382666
CutoffMode cutoff_mode = CutoffMode_TotalLength;
@@ -2675,14 +2703,21 @@ Dragon4_Scientific_AnySize(void *val, size_t size, DigitMode digit_mode,
26752703
#endif
26762704
#ifdef NPY_FLOAT128
26772705
case 16:
2706+
/* Numpy 1.14 does not support the DOUBLE_DOUBLE format properly */
2707+
#if defined(HAVE_LDOUBLE_DOUBLE_DOUBLE_BE) || \
2708+
defined(HAVE_LDOUBLE_DOUBLE_DOUBLE_LE)
2709+
PyOS_snprintf(repr, sizeof(repr), "%.*Le", precision,
2710+
*(npy_float128*)val);
2711+
#else
26782712
buf128.floatingPoint = *(npy_float128*)val;
26792713
val128.integer[0] = buf128.integer.a;
26802714
val128.integer[1] = buf128.integer.b;
26812715
Dragon4_PrintFloat128(repr, sizeof(repr), val128,
26822716
1, digit_mode, cutoff_mode, precision, sign,
26832717
trim, pad_left, -1, exp_digits);
2718+
#endif /* DOUBLE_DOUBLE */
26842719
break;
2685-
#endif
2720+
#endif /* NPY_FLOAT128 */
26862721
default:
26872722
PyErr_Format(PyExc_ValueError, "unexpected itemsize %zu", size);
26882723
return NULL;

0 commit comments

Comments
 (0)
0