-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path_global.cpp
More file actions
57 lines (45 loc) · 1.36 KB
/
Copy path_global.cpp
File metadata and controls
57 lines (45 loc) · 1.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#include <cmath>
#include <stdint.h>
typedef union
{
double value;
uint64_t ull;
struct { uint32_t low; uint32_t high; };
} T;
static inline double Convert(uint64_t ull)
{
double *value = (double*)&ull;
return *value;
}
static inline uint64_t Convert(const double &value)
{
uint64_t *ull = (uint64_t*)&value;
return *ull;
}
static double double_POSITIVE_INFINITY = Convert((uint64_t)0x7FF0000000000000ull);
static double double_NEGATIVE_INFINITY = Convert((uint64_t)0xFFF0000000000000ull);
static double double_NAN = Convert((uint64_t)0x7FF8000000000000ull);
//Является ли значение числом.
bool isFinite(double a) { return std::isfinite(a); }
//Является ли значение бесконечностью.
//POSITIVE_INFINITY
//NEGATIVE_INFINITY
bool isInf(double value)
{
const T *t = (const T*)&value;
uint32_t low = t->low;
uint32_t high = t->high;
low |= (high & 0x7fffffff) ^ 0x7ff00000;
low |= -low;
return (~(low >> 31) & (high >> 30)) != 0;
}
double POSITIVE_INFINITY() { return double_POSITIVE_INFINITY; } //Infinity
double NEGATIVE_INFINITY() { return double_NEGATIVE_INFINITY; }
double NaN() { return double_NAN; }
bool isNaN(double value)
{
uint64_t h = Convert(value);
h &= 0x7fffffffffffffffull;
h = 0x7ff0000000000000ull - h;
return (bool)(((uint64_t)h)>>63);
}