/* This file is intended to be used as input file for 'Rcpp::sourceCPP()'. * * The provided function will translate our key data structure back into human * readable double values also interpretable by R or other languages. */ #include #include #include #include using DHT_Keyelement = struct keyelem { std::int8_t exp : 8; std::int64_t significant : 56; }; using namespace Rcpp; // [[Rcpp::export]] std::vector rcpp_key_convert(std::vector input) { std::vector output; output.reserve(input.size()); for (const double &value : input) { DHT_Keyelement currKeyelement = *((DHT_Keyelement *)&value); double normalize = ((std::int32_t)-std::log10(std::fabs(currKeyelement.significant))) + currKeyelement.exp; output.push_back(currKeyelement.significant * std::pow(10., normalize)); } return output; } // [[Rcpp::export]] std::vector rcpp_uint64_convert(std::vector input) { std::vector output; output.reserve(input.size()); for (double &value : input) { std::uint64_t *as_int = reinterpret_cast(&value); output.push_back(*as_int); } return output; }