The definition and determination of invalid values of C++ floating point Numbers are analyzed

  • 2020-04-01 23:35:00
  • OfStack

Invalid floating point data may appear in the actual calculation. The formatted output to the file is 1.79769e+308, and the output to the interface is a large string of data. Either way is not very convenient for reading and searching. Invalid floating point data encountered during development is worth judging.

Invalid value definition As follows:
# define InvalidDouble * * (double) (" \ XFF \ XFF \ XFF \ XFF \ XFF \ XFF \ xef \ x7f ")
A double   Price;
. (calculation steps are omitted)
Price = GetPrice (); // get data

Floating-point is treated as follows Invalid data determination method
(price = = InvalidDouble)? 0: price,

Related articles: