-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMyMath.cpp
More file actions
46 lines (41 loc) · 938 Bytes
/
Copy pathMyMath.cpp
File metadata and controls
46 lines (41 loc) · 938 Bytes
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
#include <stdint.h>
#include <QRandomGenerator>
namespace MyMath
{
namespace
{
typedef union
{
double value;
uint64_t ull;
struct { uint32_t low; uint32_t high; };
} T;
}
//Является ли значение числом.
//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 random()
{
return QRandomGenerator::global()->generateDouble();
}
/*
bool isNaN(double value)
{
ulonglong h = Convert(value);
h &= 0x7fffffffffffffffull;
h = 0x7ff0000000000000ull - h;
return (bool)(((ulonglong)h)>>63);
}
*/
}