MCPcopy Create free account
hub / github.com/apache/arrow / generate_canonical

Function generate_canonical

cpp/src/arrow/testing/uniform_real.h:41–53  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

39// https://en.cppreference.com/w/cpp/numeric/random/generate_canonical
40template <typename RealType, typename Rng>
41RealType generate_canonical(Rng& rng) {
42 const size_t b = std::numeric_limits<RealType>::digits;
43 const size_t log2R =
44 63 - std::countl_zero(static_cast<uint64_t>(Rng::max() - Rng::min()) + 1);
45 const size_t k = b / log2R + (b % log2R != 0) + (b == 0);
46 const RealType r = static_cast<RealType>(Rng::max() - Rng::min()) + 1;
47 RealType base = r;
48 RealType sp = static_cast<RealType>(rng() - Rng::min());
49 for (size_t i = 1; i < k; ++i, base *= r) {
50 sp += (rng() - Rng::min()) * base;
51 }
52 return sp / base;
53}
54
55} // namespace detail
56

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected