Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
53 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#include <iostream> | ||
|
||
int main() { | ||
using namespace std; | ||
cout << "Hello world" << endl; | ||
return 0; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
#include <iostream> | ||
#include <cmath> | ||
#include <stdint.h> | ||
#include <limits> | ||
|
||
using std::cout; | ||
using std::endl; | ||
|
||
static bool my_isnan1(double val) { | ||
union { double f; uint64_t x; } u = { val }; | ||
return (u.x << 1) > 0x7ff0000000000000u; | ||
} | ||
|
||
static bool my_isnan2(double val) { | ||
return val != val; | ||
} | ||
|
||
static bool my_isnan3(double val) { | ||
volatile double a = val; | ||
return a != a; | ||
} | ||
|
||
static void check_nan(double val) { | ||
cout << "value: " << val << endl; | ||
cout << std::isnan(val) << endl; | ||
cout << ::isnan(val) << endl; | ||
cout << __isnan(val) << endl; | ||
cout << my_isnan1(val) << endl; | ||
cout << my_isnan2(val) << endl; | ||
cout << my_isnan3(val) << endl; | ||
} | ||
|
||
int main() { | ||
double a = std::log(0.0); | ||
cout << std::isinf(a) << endl; | ||
|
||
double b = std::sqrt(-1.0); | ||
check_nan(b); | ||
|
||
double c = std::numeric_limits<double>::quiet_NaN(); | ||
check_nan(c); | ||
|
||
return 0; | ||
} | ||
|