-
Notifications
You must be signed in to change notification settings - Fork 11
/
single.h
69 lines (55 loc) · 1.69 KB
/
single.h
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
58
59
60
61
62
63
64
65
66
67
68
69
#ifndef SINGLE_H
#define SINGLE_H
#include "InkCanvas_global.h"
#include <cmath>
#include <cstdint>
INKCANVAS_BEGIN_NAMESPACE
class Single
{
public:
//
// constants
//
static constexpr float MinValue = -3.40282346638528859e+38f;
static constexpr float Epsilon = 1.4e-45f;
static constexpr float MaxValue = 3.40282346638528859e+38f;
static const float PositiveInfinity;
static const float NegativeInfinity;
static const float NaN;
static bool IsInfinity(float f) {
return (*reinterpret_cast<uint32_t*>(&f) & 0x7FFFFFFF) == 0x7F800000;
}
static bool IsPositiveInfinity(float f) {
return *reinterpret_cast<uint32_t*>(&f) == 0x7F800000;
}
static bool IsNegativeInfinity(float f) {
return *reinterpret_cast<uint32_t*>(&f) == 0xFF800000;
}
static bool IsNaN(float f) {
return (*reinterpret_cast<uint32_t*>(&f) & 0x7FFFFFFF) > 0x7F800000;
}
// Compares this object to another object, returning an integer that
// indicates the relationship.
// Returns a value less than zero if this object
// null is considered to be less than any instance.
// If object is not of type Single, this method throws an ArgumentException.
//
int Compare(float l, float r) {
if (l < r) return -1;
if (l > r) return 1;
if (l == r) return 0;
// At least one of the values is NaN.
if (IsNaN(l))
return (IsNaN(r) ? 0 : -1);
else // f is NaN.
return 1;
}
static bool Equals(float l, float r) {
if (l == r) {
return true;
}
return IsNaN(l) && IsNaN(r);
}
};
INKCANVAS_END_NAMESPACE
#endif // SINGLE_H