File: convert.cpp

package info (click to toggle)
r-cran-dqrng 0.2.1%2Bdfsg-4
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 452 kB
  • sloc: cpp: 615; ansic: 154; sh: 14; makefile: 2
file content (41 lines) | stat: -rw-r--r-- 959 bytes parent folder | download | duplicates (3)
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
// [[Rcpp::plugins(cpp11)]]

#include <Rcpp.h>
// [[Rcpp::depends(dqrng)]]
#include "convert_seed.h"

#include <string>
#include <sstream>

template<typename U>
std::string convert_base(Rcpp::IntegerVector seed) {
    U out=dqrng::convert_seed<U>(seed);
    std::stringstream ss;
    ss << out;
    return ss.str();
}

// [[Rcpp::export]]
std::string convert_16(Rcpp::IntegerVector seed) {
    return convert_base<uint16_t>(seed);
}

// [[Rcpp::export]]
std::string convert_32(Rcpp::IntegerVector seed) {
    return convert_base<uint32_t>(seed);
}

// [[Rcpp::export]]
std::string convert_64(Rcpp::IntegerVector seed) {
    return convert_base<uint64_t>(seed);
}

// [[Rcpp::export]]
bool is_signed_consistent(Rcpp::IntegerVector seed) {
    uint64_t val=dqrng::convert_seed<uint64_t>(seed);

    std::vector<uint32_t> casted(seed.begin(), seed.end());
    uint64_t comp=dqrng::convert_seed<uint64_t>(casted.data(), casted.size());

    return (val==comp);
}