#include <cfloat>
#include <iostream>
using namespace std;
int main()
{
  double one;
  double zero;
  one = 1.0;
  zero = 0.0;
  cout << std::isinf   (one /zero) << " "; // 1
  cout << std::isinf   (zero/one ) << " "; // 0
  cout << std::isfinite(one /zero) << " "; // 0
  cout << std::isfinite(zero/one ) << " "; // 1
 
  cout << endl;
  return 0;
}
// Output: 1 0 0 1
Reference: http://en.cppreference.com/w/cpp/numeric/math/isinf
Monday, December 11, 2017
C++11: std::isinf()
C++11 added the function std::isinf() to test if a number is (+/-)infinite, and std::isfinite() to test the opposite. Here is an example:
Subscribe to:
Post Comments (Atom)

No comments:
Post a Comment