Skip to content

Commit

Permalink
Merge pull request brucefan1983#697 from brucefan1983/check_nan
Browse files Browse the repository at this point in the history
Check nan and inf
  • Loading branch information
brucefan1983 committed Aug 15, 2024
2 parents ac309c8 + 74c8d18 commit 47a5bcc
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/utilities/error.cu
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
*/

#include "error.cuh"
#include <cmath>
#include <cstring>
#include <errno.h>
#include <fstream>
Expand Down Expand Up @@ -176,6 +177,14 @@ float get_float_from_token(const std::string& token, const char* filename, const
std::cout << " Error message: " << e.what() << std::endl;
exit(1);
}
if (std::isinf(value)) {
std::cout << "This number is inf.\n";
exit(1);
}
if (std::isnan(value)) {
std::cout << "This number is nan.\n";
exit(1);
}
return value;
}

Expand All @@ -191,5 +200,13 @@ double get_double_from_token(const std::string& token, const char* filename, con
std::cout << " Error message: " << e.what() << std::endl;
exit(1);
}
if (std::isinf(value)) {
std::cout << "This number is inf.\n";
exit(1);
}
if (std::isnan(value)) {
std::cout << "This number is nan.\n";
exit(1);
}
return value;
}

0 comments on commit 47a5bcc

Please sign in to comment.