Opened 9 years ago
Closed 9 years ago
#6138 closed defect (fixed)
Incorrect negative NAN behavior in cpl_strtod.cpp:CPLStrtodDelim
Reported by: | Kurt Schwehr | Owned by: | warmerdam |
---|---|---|---|
Priority: | normal | Milestone: | |
Component: | default | Version: | svn-trunk |
Severity: | normal | Keywords: | |
Cc: |
Description
-1.#QNAN ends up giving back a NAN rather than -NAN. That seems to be wrong.
source:trunk/gdal/port/cpl_strtod.cpp#L265
It could just do:
#include <limits> // snip return -std::numeric_limits<double>::quiet_NaN();
What are the implications of changing this?
if (nptr[0] == '-') { if (strcmp(nptr, "-1.#QNAN") == 0 || strcmp(nptr, "-1.#IND") == 0) { if( endptr ) *endptr = (char*)nptr + strlen(nptr); return NAN; }
to
if (nptr[0] == '-') { if (strcmp(nptr, "-1.#QNAN") == 0 || strcmp(nptr, "-1.#IND") == 0) { if( endptr ) *endptr = (char*)nptr + strlen(nptr); return -std::numeric_limits<double>::quiet_NaN(); }
Change History (6)
comment:1 by , 9 years ago
follow-up: 3 comment:2 by , 9 years ago
Trying out limit and quiet_NaN via r30769
Note that I see comments to the effect of Tru64 support around the isnan. Do we need to support Tru64 for gdal >= 2.1.0 when support for the os was EOL'ed 3 years ago? If we support platforms with NaN and Inf issues, wht is the current list?
comment:3 by , 9 years ago
Note that I see comments to the effect of Tru64 support around the isnan. Do we need to support Tru64 for gdal >= 2.1.0 when support for the os was EOL'ed 3 years ago?
Probably not. I've hardly heard about that platform before
If we support platforms with NaN and Inf issues, wht is the current list?
No idea... GDAL at least compiles on most Debian architectures ( https://packages.debian.org/wheezy/gdal-bin ), not sure about the runtime correctness however. Plus some BSD's. Plus Android.
comment:4 by , 9 years ago
Reapplied argdataset.cpp nan test as r30781. It appears to work in travis-ci runs.
comment:6 by , 9 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
Going to call this done. I think the current behavior is fine now that we have the std:: way of specifying NaNs and Inf.
Here is the proposed patch. Will this work with MSVC compilers, Android etc?
cpl_strtod.cpp
#include <errno.h>#include <stdlib.h>#ifndef NAN# ifdef HUGE_VAL# define NAN (HUGE_VAL * 0.0)# elsestatic float CPLNaN(void){float fNan;int nNan = 0x7FC00000;memcpy(&fNan, &nNan, 4);return fNan;}# define NAN CPLNan()# endif#endif#ifndef INFINITYstatic CPL_INLINE double CPLInfinity(void){static double ZERO = 0;return 1.0 / ZERO; /* MSVC doesn't like 1.0 / 0.0 */}#define INFINITY CPLInfinity()static CPL_INLINE double CPLNegInfinity(void){static double ZERO = 0;return -1.0 / ZERO; /* MSVC doesn't like -1.0 / 0.0 */}#define NEG_INFINITY CPLNegInfinity()#else#define NEG_INFINITY (-INFINITY)#endifNAN;NEG_INFINITY;NAN;INFINITY;INFINITY;NAN;