diff options
| author | Charles Harris <charlesr.harris@gmail.com> | 2008-04-11 01:54:18 +0000 |
|---|---|---|
| committer | Charles Harris <charlesr.harris@gmail.com> | 2008-04-11 01:54:18 +0000 |
| commit | afa44063ca0ff29e39de5d7c2b6424838f6a0cec (patch) | |
| tree | d46f0cd854d9a3ef40f71eb801ecf512c84603ab /numpy | |
| parent | 032390044e1d990da1b571b9a8f150464e479d67 (diff) | |
| download | numpy-afa44063ca0ff29e39de5d7c2b6424838f6a0cec.tar.gz | |
Add functions for str instead of defining them to the same as repr. Reduce repr
precision of longdouble to 20 and set str precision of longdouble to the same as
double. This is a first cut at looking through the formatting used to print
numbers.
The precisions are now
#define FLOATPREC_REPR 8
#define FLOATPREC_STR 6
#define DOUBLEPREC_REPR 17
#define DOUBLEPREC_STR 12
#if SIZEOF_LONGDOUBLE == SIZEOF_DOUBLE
#define LONGDOUBLEPREC_REPR DOUBLEPREC_REPR
#define LONGDOUBLEPREC_STR DOUBLEPREC_STR
#else /* More than probably needed on Intel FP */
#define LONGDOUBLEPREC_REPR 20
#define LONGDOUBLEPREC_STR 12
#endif
This line, and those below, will be ignored--
M numpy/core/src/scalartypes.inc.src
Diffstat (limited to 'numpy')
| -rw-r--r-- | numpy/core/src/scalartypes.inc.src | 48 |
1 files changed, 37 insertions, 11 deletions
diff --git a/numpy/core/src/scalartypes.inc.src b/numpy/core/src/scalartypes.inc.src index 6b374e36f..594277d8c 100644 --- a/numpy/core/src/scalartypes.inc.src +++ b/numpy/core/src/scalartypes.inc.src @@ -610,16 +610,49 @@ static PyObject * /* These values are finfo.precision + 2 */ #define FLOATPREC_REPR 8 +#define FLOATPREC_STR 6 #define DOUBLEPREC_REPR 17 - +#define DOUBLEPREC_STR 12 #if SIZEOF_LONGDOUBLE == SIZEOF_DOUBLE #define LONGDOUBLEPREC_REPR DOUBLEPREC_REPR -#define LONGDOUBLEPREC_STR DOUBLEPREC_REPR +#define LONGDOUBLEPREC_STR DOUBLEPREC_STR #else /* More than probably needed on Intel FP */ -#define LONGDOUBLEPREC_REPR 22 -#define LONGDOUBLEPREC_STR 22 +#define LONGDOUBLEPREC_REPR 20 +#define LONGDOUBLEPREC_STR 12 #endif +/* floattype_str */ +/**begin repeat + +#name=float, double, longdouble# +#Name=Float, Double, LongDouble# +#NAME=FLOAT, DOUBLE, LONGDOUBLE# +*/ +static PyObject * +@name@type_str(PyObject *self) +{ + static char buf[100]; + format_@name@(buf, sizeof(buf), + ((Py@Name@ScalarObject *)self)->obval, @NAME@PREC_STR); + return PyString_FromString(buf); +} + +static PyObject * +c@name@type_str(PyObject *self) +{ + static char buf1[100]; + static char buf2[100]; + static char buf3[202]; + c@name@ x; + x = ((PyC@Name@ScalarObject *)self)->obval; + format_@name@(buf1, sizeof(buf1), x.real, @NAME@PREC_STR); + format_@name@(buf2, sizeof(buf2), x.imag, @NAME@PREC_STR); + + snprintf(buf3, sizeof(buf3), "(%s+%sj)", buf1, buf2); + return PyString_FromString(buf3); +} +/**end repeat**/ + /* floattype_repr */ /**begin repeat @@ -652,13 +685,6 @@ c@name@type_repr(PyObject *self) } /**end repeat**/ -/**begin repeat - -#name=float, double, longdouble# -*/ -#define @name@type_str @name@type_repr -#define c@name@type_str c@name@type_repr -/**end repeat**/ /** Could improve this with a PyLong_FromLongDouble(longdouble ldval) but this would need some more work... |
