diff options
author | Anne Archibald <archibald@astron.nl> | 2015-08-12 17:46:14 +0200 |
---|---|---|
committer | Anne Archibald <archibald@astron.nl> | 2015-08-28 15:52:42 +0200 |
commit | 6cbd724f75f25cdaa7cf68fd9743064b77fbf787 (patch) | |
tree | 816e86d5806f60c9e2bd618fe3874a6bec373e10 /numpy/lib/_iotools.py | |
parent | b478ded953395fee6182439ff5e8eb38fd4271ce (diff) | |
download | numpy-6cbd724f75f25cdaa7cf68fd9743064b77fbf787.tar.gz |
BUG: fix #4381: precision loss on string -> longdouble conversion
Avoid going through python floats when converting string to
longdouble. This makes it dramatically easier to produce
full-precision long double numbers. Fixed are the constructor
(np.longdouble("1.01")), np.fromfile, np.fromstring, np.loadtxt,
and np.genfromtxt (and functions based on it). Also fixed is
precision loss when using np.tofile.
This also fixes #1481, poor handling of bad data in fromfile
and fromstring.
If the function strtod_l is not available, almost none of this
will work, and many tests will fail.
Diffstat (limited to 'numpy/lib/_iotools.py')
-rw-r--r-- | numpy/lib/_iotools.py | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/numpy/lib/_iotools.py b/numpy/lib/_iotools.py index 44bd48df7..dfdc38b72 100644 --- a/numpy/lib/_iotools.py +++ b/numpy/lib/_iotools.py @@ -527,6 +527,7 @@ class StringConverter(object): _mapper.extend([(nx.floating, float, nx.nan), (complex, _bytes_to_complex, nx.nan + 0j), + (nx.longdouble, nx.longdouble, nx.nan), (nx.string_, bytes, asbytes('???'))]) (_defaulttype, _defaultfunc, _defaultfill) = zip(*_mapper) @@ -643,6 +644,18 @@ class StringConverter(object): else: self.default = default break + # if a converter for the specific dtype is available use that + last_func = func + for (i, (deftype, func, default_def)) in enumerate(self._mapper): + if dtype.type == deftype: + _status = i + last_func = func + if default is None: + self.default = default_def + else: + self.default = default + break + func = last_func if _status == -1: # We never found a match in the _mapper... _status = 0 |