ritsuko
Helper utilities for ArtifactDB C++ code
Loading...
Searching...
No Matches
r_missing_value.hpp
Go to the documentation of this file.
1#ifndef RITSUKO_R_MISSING_HPP
2#define RITSUKO_R_MISSING_HPP
3
4#include <cstdint>
5#include <cstring>
6
12namespace ritsuko {
13
19inline double r_missing_value() {
20 uint32_t tmp_value = 1;
21 auto tmp_ptr = reinterpret_cast<unsigned char*>(&tmp_value);
22
23 // Mimic R's generation of these values, but we can't use type punning as
24 // this is not legal in C++, and we don't have bit_cast yet.
25 double missing_value = 0;
26 auto missing_ptr = reinterpret_cast<unsigned char*>(&missing_value);
27
28 int step = 1;
29 if (tmp_ptr[0] == 1) { // little-endian.
30 missing_ptr += sizeof(double) - 1;
31 step = -1;
32 }
33
34 *missing_ptr = 0x7f;
35 *(missing_ptr += step) = 0xf0;
36 *(missing_ptr += step) = 0x00;
37 *(missing_ptr += step) = 0x00;
38 *(missing_ptr += step) = 0x00;
39 *(missing_ptr += step) = 0x00;
40 *(missing_ptr += step) = 0x07;
41 *(missing_ptr += step) = 0xa2;
42
43 return missing_value;
44}
45
56template<typename Float_>
57bool are_floats_identical(const Float_* x, const Float_* y) {
58 auto xptr = reinterpret_cast<const unsigned char*>(x);
59 auto yptr = reinterpret_cast<const unsigned char*>(y);
60 return std::memcmp(xptr, yptr, sizeof(Float_)) == 0;
61}
62
63}
64
65#endif
Assorted helper functions for parsing and validation.
Definition choose_missing_placeholder.hpp:15
bool are_floats_identical(const Float_ *x, const Float_ *y)
Definition r_missing_value.hpp:57
double r_missing_value()
Definition r_missing_value.hpp:19