Skip to content

Commit 47a5bcc

Browse files
authored
Merge pull request brucefan1983#697 from brucefan1983/check_nan
Check nan and inf
2 parents ac309c8 + 74c8d18 commit 47a5bcc

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

src/utilities/error.cu

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
*/
1515

1616
#include "error.cuh"
17+
#include <cmath>
1718
#include <cstring>
1819
#include <errno.h>
1920
#include <fstream>
@@ -176,6 +177,14 @@ float get_float_from_token(const std::string& token, const char* filename, const
176177
std::cout << " Error message: " << e.what() << std::endl;
177178
exit(1);
178179
}
180+
if (std::isinf(value)) {
181+
std::cout << "This number is inf.\n";
182+
exit(1);
183+
}
184+
if (std::isnan(value)) {
185+
std::cout << "This number is nan.\n";
186+
exit(1);
187+
}
179188
return value;
180189
}
181190

@@ -191,5 +200,13 @@ double get_double_from_token(const std::string& token, const char* filename, con
191200
std::cout << " Error message: " << e.what() << std::endl;
192201
exit(1);
193202
}
203+
if (std::isinf(value)) {
204+
std::cout << "This number is inf.\n";
205+
exit(1);
206+
}
207+
if (std::isnan(value)) {
208+
std::cout << "This number is nan.\n";
209+
exit(1);
210+
}
194211
return value;
195212
}

0 commit comments

Comments
 (0)