llvm-project/libcxx/include/__random
Louis Dionne 07e984bc52 [libc++] Support int8_t and uint8_t in integer distributions as an extension
In D125283, we ensured that integer distributions would not compile when
used with arbitrary unsupported types. This effectively enforced what
the Standard mentions here: http://eel.is/c++draft/rand#req.genl-1.5.

However, this also had the effect of breaking some users that were
using integer distributions with unsupported types like int8_t. Since we
already support using __int128_t in those distributions, it is reasonable
to also support smaller types like int8_t and its unsigned variant. This
commit implements that, adds tests and documents the extension. Note that
we voluntarily don't add support for instantiating these distributions
with bool and char, since those are not integer types. However, it is
trivial to replace uses of these random distributions on char using int8_t.

It is also interesting to note that in the process of adding tests
for smaller types, I discovered that our distributions sometimes don't
provide as faithful a distribution when instantiated with smaller types,
so I had to relax a couple of tests. In particular, we do a really bad
job at implementing the negative binomial, geometric and poisson distributions
for small types. I think this all boils down to the algorithm we use in
std::poisson_distribution, however I am running out of time to investigate
that and changing the algorithm would be an ABI break (which might be
reasonable).

As part of this patch, I also added a mitigation for a very likely
integer overflow bug we were hitting in our tests in negative_binomial_distribution.
I also filed http://llvm.org/PR56656 to track fixing the problematic
distributions with int8_t and uint8_t.

Supersedes D125283.

Differential Revision: https://reviews.llvm.org/D126823
2022-07-22 08:33:01 -04:00
..
bernoulli_distribution.h [libc++] Explicitly reject URNG types with signed result_types. 2022-03-02 10:28:48 -05:00
binomial_distribution.h [libc++] Support int8_t and uint8_t in integer distributions as an extension 2022-07-22 08:33:01 -04:00
cauchy_distribution.h [libc++] Explicitly reject URNG types with signed result_types. 2022-03-02 10:28:48 -05:00
chi_squared_distribution.h [libc++] Revert "Protect users from relying on detail headers" & related changes 2022-03-01 08:20:24 -05:00
clamp_to_integral.h [libc++] Revert "Protect users from relying on detail headers" & related changes 2022-03-01 08:20:24 -05:00
default_random_engine.h [libc++] Revert "Protect users from relying on detail headers" & related changes 2022-03-01 08:20:24 -05:00
discard_block_engine.h [libc++] Revert "Protect users from relying on detail headers" & related changes 2022-03-01 08:20:24 -05:00
discrete_distribution.h [libc++] Support int8_t and uint8_t in integer distributions as an extension 2022-07-22 08:33:01 -04:00
exponential_distribution.h [libc++] Explicitly reject URNG types with signed result_types. 2022-03-02 10:28:48 -05:00
extreme_value_distribution.h [libc++] Explicitly reject URNG types with signed result_types. 2022-03-02 10:28:48 -05:00
fisher_f_distribution.h [libc++] Explicitly reject URNG types with signed result_types. 2022-03-02 10:28:48 -05:00
gamma_distribution.h [libc++] Explicitly reject URNG types with signed result_types. 2022-03-02 10:28:48 -05:00
generate_canonical.h [libc++] Revert "Protect users from relying on detail headers" & related changes 2022-03-01 08:20:24 -05:00
geometric_distribution.h [libc++] Support int8_t and uint8_t in integer distributions as an extension 2022-07-22 08:33:01 -04:00
independent_bits_engine.h [libc++] Revert "Protect users from relying on detail headers" & related changes 2022-03-01 08:20:24 -05:00
is_seed_sequence.h [libc++] Revert "Protect users from relying on detail headers" & related changes 2022-03-01 08:20:24 -05:00
is_valid.h [libc++] Support int8_t and uint8_t in integer distributions as an extension 2022-07-22 08:33:01 -04:00
knuth_b.h [libc++] Revert "Protect users from relying on detail headers" & related changes 2022-03-01 08:20:24 -05:00
linear_congruential_engine.h [libc++] Define _LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER whenever we enable warnings in the test suite 2022-03-15 17:17:54 -04:00
log2.h [libc++] Revert "Protect users from relying on detail headers" & related changes 2022-03-01 08:20:24 -05:00
lognormal_distribution.h [libc++] Revert "Protect users from relying on detail headers" & related changes 2022-03-01 08:20:24 -05:00
mersenne_twister_engine.h [libc++] Revert "Protect users from relying on detail headers" & related changes 2022-03-01 08:20:24 -05:00
negative_binomial_distribution.h [libc++] Support int8_t and uint8_t in integer distributions as an extension 2022-07-22 08:33:01 -04:00
normal_distribution.h [libc++] Explicitly reject URNG types with signed result_types. 2022-03-02 10:28:48 -05:00
piecewise_constant_distribution.h [libc++] Make parameter names consistent and enforce the naming style using readability-identifier-naming 2022-07-08 18:17:47 +02:00
piecewise_linear_distribution.h [libc++] Make parameter names consistent and enforce the naming style using readability-identifier-naming 2022-07-08 18:17:47 +02:00
poisson_distribution.h [libc++] Support int8_t and uint8_t in integer distributions as an extension 2022-07-22 08:33:01 -04:00
random_device.h [libc++] Revert "Protect users from relying on detail headers" & related changes 2022-03-01 08:20:24 -05:00
ranlux.h [libc++] Revert "Protect users from relying on detail headers" & related changes 2022-03-01 08:20:24 -05:00
seed_seq.h [libc++] Replace modulus operations in std::seed_seq::generate with conditional checks. 2022-05-24 10:29:25 +02:00
shuffle_order_engine.h [libc++] Revert "Protect users from relying on detail headers" & related changes 2022-03-01 08:20:24 -05:00
student_t_distribution.h [libc++] Explicitly reject URNG types with signed result_types. 2022-03-02 10:28:48 -05:00
subtract_with_carry_engine.h [libc++] Revert "Protect users from relying on detail headers" & related changes 2022-03-01 08:20:24 -05:00
uniform_int_distribution.h [libc++] Support int8_t and uint8_t in integer distributions as an extension 2022-07-22 08:33:01 -04:00
uniform_random_bit_generator.h [libc++] Replace _LIBCPP_HAS_NO_CONCEPTS with _LIBCPP_STD_VER > 17. NFCI. 2022-03-13 12:32:06 -04:00
uniform_real_distribution.h [libc++] Explicitly reject URNG types with signed result_types. 2022-03-02 10:28:48 -05:00
weibull_distribution.h [libc++] Revert "Protect users from relying on detail headers" & related changes 2022-03-01 08:20:24 -05:00