Val! = Std :: numeric_limits <double> :: infinity () or! isinf (val) or isfinite (val)
Most likely bike-shedding , but maybe there is something interesting that I'm missing ...
If the class initializes the member val
before std::numeric_limits<double>::infinity()
, and later wants to check if the val value has been changed to something real (+/- inf are invalid here), what are the tradeoffs of these three approaches and I miss other interesting ways to solve this problem. (remote const for readability in the examples.)
bool IsInit() { return MinX != std::numeric_limits<double>::infinity(); } // a
bool IsInit() { return !std::isinf(MinX); } // b
bool IsInit() { return std::isfinite(MinX); } // c
At the moment, the code is C ++ 03, but how to change the parameters using C ++ 11, C ++ 14 and C ++ 17. For example, with C ++ 17 this code can be simple std::optional<double> val
. Or would it be safer for NaN to be a safer bet, just incase +/- inf became valid in the future?
This happened when I read this patch for this code:
- https://github.com/OSGeo/gdal/commit/30194c640f403008625ff0c8be7aca155ac7ebe1
- https://trac.osgeo.org/gdal/browser/trunk/gdal/ogr/ogr_core.h?rev=37821#L76
For convenience:
- std :: numeric_limits :: infinity ()
- std :: isinf
- std :: isfinite
- std :: numeric_limits :: quiet_NaN
- std :: optional
Relatively related:
, . , . . NaN, , , , , .
, "" . , , , . , , : , .
, , OGREnvelope
(, , AABB) github, , :
IsInit
- - , , AABB . , /,IsInit
( ).IsValid
.- , , , , AABB
MinX
, ,MaxX
,MinY
, ,MaxY
. , AABB.MinX
MaxX
( min max Y). - , , : (a) AABB AABB ( , 14 4); (b) AABB,
max()
lowest()
. - , -
MinX
,MaxX
,MinY
,MaxY
, ,IsInit
, .
, NaN . , MinX != std::numeric_limits<double>::infinity()
. IsInit
( ) . IsValid
, :
bool IsValid() const
{
return !std::isnan(MinX) && !std::isnan(MinY) && MinX <= MaxX && MinY <= MaxY;
}
AABB OGREnvelope
, ( NaN), X Y .
, , , , .
, Godbolt: https://godbolt.org/z/184Zb6
, std::numeric_limits<double>::infinity()
( ), std::isfinite()
; !std::isinf()
, , !std::isinf()
- .