Skip to content

Instantly share code, notes, and snippets.

@ashwin
Created January 5, 2015 02:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ashwin/a29abf880ef66a0ca45f to your computer and use it in GitHub Desktop.
Save ashwin/a29abf880ef66a0ca45f to your computer and use it in GitHub Desktop.
How to check for math error in C++
// Checking for math error in C++
#include <cerrno>
#include <cmath>
#include <cstring>
#include <iostream>
std::cout << log(0) << std::endl;
if (errno)
std::cout << std::strerror(errno) << std::endl;
if (errno == EDOM)
std::cout << "Domain error\n";
if (errno == ERANGE)
std::cout << "Range error\n";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment