algotradelib
0.0.0.9000
C++ header-only library for algorithmic trading
Toggle main menu visibility
Loading...
Searching...
No Matches
scalar.hpp
1
#pragma once
2
3
#include <cmath>
4
#include <cstddef>
5
#include <cstdint>
6
#include <cstring>
7
#include <limits>
8
9
namespace
algotradelib
{
10
namespace
math
{
11
18
using
Scalar
= double;
19
28
inline
Scalar
missing
() {
return
std::numeric_limits<Scalar>::quiet_NaN(); }
29
36
inline
bool
observed
(
Scalar
value) {
return
!std::isnan(value); }
37
51
inline
Scalar
undefined
() {
52
// A quiet NaN with a distinguishing payload: exponent all ones, quiet bit set, and a
53
// payload no library produces by accident.
54
static_assert
(
sizeof
(
Scalar
) ==
sizeof
(std::uint64_t),
"undefined() assumes a 64-bit Scalar"
);
55
const
std::uint64_t bits = 0x7FF80000000F1A7EULL;
56
Scalar
value;
57
std::memcpy(&value, &bits,
sizeof
(value));
58
return
value;
59
}
60
69
inline
bool
is_undefined
(
Scalar
value) {
70
if
(!std::isnan(value)) {
71
return
false
;
72
}
73
std::uint64_t bits{0};
74
std::memcpy(&bits, &value,
sizeof
(bits));
75
// Compares the payload only, masking off the sign, the exponent, and the quiet bit, so a
76
// negated or re-quieted copy still reads as the same marker.
77
return
(bits & 0x0007FFFFFFFFFFFFULL) == 0x000F1A7EULL;
78
}
79
80
}
// namespace math
81
}
// namespace algotradelib
algotradelib::math
The numeric vocabulary: Scalar, missing(), and the matrix and vector types.
Definition
eigen.hpp:10
algotradelib::math::is_undefined
bool is_undefined(Scalar value)
Tests whether a value is the undefined() marker.
Definition
scalar.hpp:69
algotradelib::math::Scalar
double Scalar
The floating-point type the analytics and math layers compute in (double).
Definition
scalar.hpp:18
algotradelib::math::observed
bool observed(Scalar value)
Tests whether a value is an observation.
Definition
scalar.hpp:36
algotradelib::math::undefined
Scalar undefined()
Returns the value that stands for "the data was there, but the statistic does not exist".
Definition
scalar.hpp:51
algotradelib::math::missing
Scalar missing()
Returns the value that stands for "no observation" (a quiet NaN).
Definition
scalar.hpp:28
algotradelib
The library: broker-neutral types (core), and the modules below.
Definition
conversion.hpp:13
algotradelib
src
math
scalar.hpp
Generated by
1.18.0