Summary
I need to produce an XML document that looks like this
<BoundingBox xmin="-INF" xmax="INF"/>
How do I set the values of xmin & xmax in the code to get -INF and INF in the output XML.
Solution - Setting
Doubles and Floats have 3 'magic' values, these can be set using the following code
| INF |
box->SetXmax(std::numeric_limits<double>::infinity()); |
| -INF |
box->SetXmin(-std::numeric_limits<double>::infinity()); |
| NaN |
box->SetXmin(std::numeric_limits<double>::quiet_NaN()); |
Note the header file limits must be included
#include
<limits>
Solution - Reading
Whe these values are present in the XML they can be detected using the following checks
| INF |
bool isPositiveInf = box->GetXmax() == std::numeric_limits<double>::infinity(); |
| -INF |
bool isPositiveInf = box->GetXmax() == std::numeric_limits<double>::infinity(); |
| NaN |
bool isNaN = box->GetXmin() == std::numeric_limits<double>::quiet_NaN();
or
#include <float.h>
...
bool isNaN = _isnan(box->GetXmin()); |