Determine if a floating point number is Nan (INF) in vc6)

Source: Internet
Author: User

Nan indicates not a number.

After Division by zero, the floating point will become Nan (INF ).

You can use the following functions to determine whether the value is Nan (INF ).

Library Function: int _ isnan (double );

Int _ finite (double); // use this function in VC

// If the input double value is invalid, the function returns 0. You need to include the library file <float. h>

You can also write user-defined functions for judgment (not in VC)

1 bool is_nan(double dVal)
2 {
3   if (dVal==dVal)
4     return false;
5
6   return true;
7 }

The invalid value in vc6 is1. # inf000000000

 This value varies with compilers.

This difference can be shielded using the C ++ standard library. The following code:

#include <limits>

bool is_nan(double dVal)
{
  double dNan = std::numeric_limits<double>::quiet_NaN();
  if (dVal==dNan)
    return true;

  return false;
}

The following functions can be used in boost to determine

#include <boost/math/special_functions/fpclassify.hpp>

template <class T> bool isfinite(T z);
template <class T> bool isinf(T t);
template <class T> bool isnan(T t);
template <class T> bool isnormal(T t);


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.