[gdal-dev] +/-infinity as an uninitialized marker

Even Rouault even.rouault at spatialys.com
Tue Mar 21 08:29:41 PDT 2017


On mardi 21 mars 2017 16:11:44 CET Mateusz Loskot wrote:
> On 21 March 2017 at 15:50, Kurt Schwehr <schwehr at gmail.com> wrote:
> > Hey Even,
> > 
> > Probably not a big deal, but I'm curious why you didn't use !isinf(MinX)
> > or
> > isfinite(MinX) for your recent OGREnvelope patch:
> > 
> > int  IsInit() const { return MinX !=
> > std::numeric_limits<double>::infinity(); }
> 
> Portability wank: it's also good idea to check for
> std::numeric_limits<number<T> >::has_infinity
> 
> eg. something like
> 
> std::numeric_limits<number<double>::has_infinity
> ? std::numeric_limits<number<double>::infinity()
> 
> : (std::numeric_limits<number<double>::max)()

Looking at http://en.cppreference.com/w/cpp/types/numeric_limits/infinity, it seems that 
std::numeric_limits<double>::infinity always resolve to some reasonable "big" value.

And looking at http://en.cppreference.com/w/cpp/types/numeric_limits/has_infinity and 
http://en.cppreference.com/w/cpp/types/numeric_limits/is_iec559, it might not be a specific 
value on some non-IEEE754 problems.

Anyway we already use  std::numeric_limits<double>::infinity() in a number of places. And 
more subtelty, we serialize/deserialize between 8 bytes stored in files and C/C++ double in a 
lot of places (an trust me, that's really a lot ! shapefile, WKB, geotiff, many drivers) assuming 
that the machine representation of double is IEEE754. So basically GDAL is only compatible 
of such machines. And apparently people using non-IEEE754 platforms are too shy to 
complain or provide compatibility patches :-)

Even

-- 
Spatialys - Geospatial professional services
http://www.spatialys.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/gdal-dev/attachments/20170321/2f05c0ae/attachment.html>


More information about the gdal-dev mailing list