[Qgis-developer] isfinite <-> std::isfinite

Mateusz Loskot mateusz at loskot.net
Sat Sep 30 12:56:43 EDT 2006


humarco wrote:
> Dear developers,
> 
> in qgswmsprovider.cpp:1954, there are the following lines of code. I have gcc 
> version 4.0.3 and this version needs 'std::isfinite' to compile.

Marco,

It's very strange libstdc++ puts isfinite to std namespace.
isinfinite is *not* in C++ standard, as well as not in C98.
This macro (as well as isnormal,isnan,isinf, etc.) is defined in C99
standard. C++ standard does not define them (is based on C98).

As I see in libstdc++ sources, this macro is wrapped by free function.
In libstdc++ 3.x, it's in global namespace, but in libstdc++ 4.x, it's
defined in std::, but it's *marked* in sources as an extension.

So, isfinite or std::isfinite is *not* portable function,
it's an extension.

> I wonder 
> from what version on it needs 'isfinite' without 'std::' . Please post your 
> compiler versions and if you need 'std::isfinite' or 'isfinite' for it.
> 
> #if __GNUC__ >= 4
>     
> if(!isfinite(extent.xMin()) || !isfinite((int)extent.yMin()) || !isfinite(extent.xMax()) || 
> \
>        !isfinite((int)extent.yMax()))
> #else
>     
> if(!std::isfinite(extent.xMin()) || !std::isfinite((int)extent.yMin()) || !std::isfinite(extent.xMax()) || 
> \
>        !std::isfinite((int)extent.yMax()))
> #endif

Isn't it better to use std::numeric_limits<T> [1] to check
numeric ranges?
Less code and better portability:

if (extent.yMax() <= std::numeric_limits<double>::max()) {}

There is also test for infinity support for given type possible:

if (std::numeric_limits<double>::has_infinity
{
    if (some_value == std::numeric_limits<double>::infinity())
   {
      // some_value is infinite
   }
}


[1] http://www.dinkumware.com/manuals/?manual=compleat&page=limits2.html

Cheers
-- 
Mateusz Loskot
http://mateusz.loskot.net



More information about the Qgis-developer mailing list