summaryrefslogtreecommitdiff
path: root/numpy/core
diff options
context:
space:
mode:
authorDavid Cournapeau <cournape@gmail.com>2008-12-28 03:18:20 +0000
committerDavid Cournapeau <cournape@gmail.com>2008-12-28 03:18:20 +0000
commit69bf86201ff2d85d9a84470ceb87797ec516f4df (patch)
tree6879ec855ee68831eebe195fda9f914fda34a18d /numpy/core
parent8a7a6c99efe9a92c062c2410e16d5b8ece6654cd (diff)
downloadnumpy-69bf86201ff2d85d9a84470ceb87797ec516f4df.tar.gz
Revert formatting changes: ascii_formatd only works for double, so we can't use it as it is for our formatting needs.
Diffstat (limited to 'numpy/core')
-rw-r--r--numpy/core/setup.py3
-rw-r--r--numpy/core/src/multiarraymodule.c2
-rw-r--r--numpy/core/src/scalartypes.inc.src92
3 files changed, 18 insertions, 79 deletions
diff --git a/numpy/core/setup.py b/numpy/core/setup.py
index 269a13538..dbae644cd 100644
--- a/numpy/core/setup.py
+++ b/numpy/core/setup.py
@@ -352,8 +352,7 @@ def configuration(parent_package='',top_path=None):
join('src','scalartypes.inc.src'),
join('src','arraytypes.inc.src'),
join(codegen_dir,'generate_numpy_api.py'),
- join('*.py'),
- join('src','umath_funcs_c99.inc.src'),
+ join('*.py')
],
depends = deps,
)
diff --git a/numpy/core/src/multiarraymodule.c b/numpy/core/src/multiarraymodule.c
index cfe5b9d9a..53ce89a94 100644
--- a/numpy/core/src/multiarraymodule.c
+++ b/numpy/core/src/multiarraymodule.c
@@ -24,8 +24,6 @@
#define PyAO PyArrayObject
-#include "config.h"
-#include "umath_funcs_c99.inc"
static PyObject *typeDict=NULL; /* Must be explicitly loaded */
diff --git a/numpy/core/src/scalartypes.inc.src b/numpy/core/src/scalartypes.inc.src
index 86dc393a3..b65f7adbc 100644
--- a/numpy/core/src/scalartypes.inc.src
+++ b/numpy/core/src/scalartypes.inc.src
@@ -604,107 +604,49 @@ gentype_repr(PyObject *self)
return ret;
}
-/* Hack to deal with mingw brokenness wrt long double support in printf */
-
-/**begin repeat
- * #name=float, double#
- * #NAME=FLOAT, DOUBLE#
- */
-#define _CAST_@NAME@(prec) (prec)
-/**end repeat**/
-#ifdef __MINGW32__
-#undef LONGDOUBLEPREC_REPR
-#undef LONGDOUBLEPREC_STR
-#define LONGDOUBLEPREC_REPR DOUBLEPREC_REPR
-#define LONGDOUBLEPREC_STR DOUBLEPREC_STR
-#define _CAST_LONGDOUBLE(prec) ((double)prec)
-#else
-#define _CAST_LONGDOUBLE(prec) (prec)
-#endif
-
-
/**begin repeat
* #name=float, double, longdouble#
* #NAME=FLOAT, DOUBLE, LONGDOUBLE#
*/
-/* Both format functions are shameless copies from python floatobject and
- * complexobject files */
+#define FMT "%.*" NPY_@NAME@_FMT
+#define CFMT1 "%.*" NPY_@NAME@_FMT "j"
+#define CFMT2 "(%.*" NPY_@NAME@_FMT "%+.*" NPY_@NAME@_FMT "j)"
+
static void
format_@name@(char *buf, size_t buflen, @name@ val, unsigned int prec)
{
int cnt, i;
- char format[32];
- register char* cp;
- PyOS_snprintf(format, sizeof(format), "%%.%i" NPY_@NAME@_FMT, prec);
- PyOS_snprintf(buf, buflen, format, _CAST_@NAME@(val));
- cp = buf;
- if (*cp == '-') {
- ++cp;
- }
+ cnt = PyOS_snprintf(buf, buflen, FMT, prec, val);
/* If nothing but digits after sign, append ".0" */
- for (; *cp != '\0'; ++cp) {
- if (!isdigit(Py_CHARMASK(*cp))) {
+ for (i = (val < 0) ? 1 : 0; i < cnt; ++i) {
+ if (!isdigit(Py_CHARMASK(buf[i]))) {
break;
}
}
-
- if (*cp == '\0') {
- cp[0] = '.';
- cp[1] = '0';
- cp[2] = '\0';
- cp += 3;
- return ;
- }
- /* Checking the next three chars should be more than enough to
- * detect inf or nan, even on Windows. We check for inf or nan
- * at last because they are rare cases.
- */
- for (i=0; *cp != '\0' && i<3; cp++, i++) {
- if (isdigit(Py_CHARMASK(*cp)) || *cp == '.') {
- continue;
- }
- /* found something that is neither a digit nor point
- * it might be a NaN or INF
- */
- if (isnan(val)) {
- strcpy(buf, "nan");
- }
- else if (isinf(val)) {
- cp = buf;
- if (*cp == '-') {
- cp++;
- }
- strcpy(cp, "inf");
- }
- break;
+ if (i == cnt && buflen >= cnt + 3) {
+ strcpy(&buf[cnt],".0");
}
}
static void
format_c@name@(char *buf, size_t buflen, c@name@ val, unsigned int prec)
{
- char format[32];
if (val.real == 0.0) {
- PyOS_snprintf(format, sizeof(format), "%%.%i" NPY_@NAME@_FMT, prec);
- PyOS_snprintf(buf, buflen - 1, format, _CAST_@NAME@(val.imag));
- strncat(buf, "j", 1);
- } else {
- char re[64], im[64];
- PyOS_snprintf(format, sizeof(format), "%%.%i" NPY_@NAME@_FMT, prec);
- PyOS_snprintf(re, sizeof(re), format, _CAST_@NAME@(val.real));
- PyOS_snprintf(format, sizeof(format), "%%+.%i" NPY_@NAME@_FMT, prec);
- PyOS_snprintf(im, sizeof(im), format, _CAST_@NAME@(val.imag));
- PyOS_snprintf(buf, buflen, "(%s%sj)", re, im);
+ PyOS_snprintf(buf, buflen, CFMT1, prec, val.imag);
+ }
+ else {
+ PyOS_snprintf(buf, buflen, CFMT2, prec, val.real, prec, val.imag);
}
}
+#undef FMT
+#undef CFMT1
+#undef CFMT2
+
/**end repeat**/
-#undef _CAST_FLOAT
-#undef _CAST_DOUBLE
-#undef _CAST_LONGDOUBLE
/* over-ride repr and str of array-scalar strings and unicode to
remove NULL bytes and then call the corresponding functions