brintos

brintos / llvm-project-archived public Read only

0
0
Text · 4.4 KiB · 1af1d85 Raw
136 lines · cpp
1//===----------------------------------------------------------------------===//2//3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.4// See https://llvm.org/LICENSE.txt for license information.5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception6//7//===----------------------------------------------------------------------===//8 9// <random>10 11// template <class UIntType, size_t w, size_t n, size_t m, size_t r,12//           UIntType a, size_t u, UIntType d, size_t s,13//           UIntType b, size_t t, UIntType c, size_t l, UIntType f>14// class mersenne_twister_engine15// {16// public:17//     // types18//     typedef UIntType result_type;19//20//     // engine characteristics21//     static constexpr size_t word_size = w;22//     static constexpr size_t state_size = n;23//     static constexpr size_t shift_size = m;24//     static constexpr size_t mask_bits = r;25//     static constexpr result_type xor_mask = a;26//     static constexpr size_t tempering_u = u;27//     static constexpr result_type tempering_d = d;28//     static constexpr size_t tempering_s = s;29//     static constexpr result_type tempering_b = b;30//     static constexpr size_t tempering_t = t;31//     static constexpr result_type tempering_c = c;32//     static constexpr size_t tempering_l = l;33//     static constexpr result_type initialization_multiplier = f;34//     static constexpr result_type min () { return 0; }35//     static constexpr result_type max() { return 2^w - 1; }36//     static constexpr result_type default_seed = 5489u;37 38#include <random>39#include <type_traits>40#include <cassert>41 42#include "test_macros.h"43 44template <class T>45void where(const T &) {}46 47void48test1()49{50    typedef std::mt19937 E;51    static_assert((E::word_size == 32), "");52    static_assert((E::state_size == 624), "");53    static_assert((E::shift_size == 397), "");54    static_assert((E::mask_bits == 31), "");55    static_assert((E::xor_mask == 0x9908b0df), "");56    static_assert((E::tempering_u == 11), "");57    static_assert((E::tempering_d == 0xffffffff), "");58    static_assert((E::tempering_s == 7), "");59    static_assert((E::tempering_b == 0x9d2c5680), "");60    static_assert((E::tempering_t == 15), "");61    static_assert((E::tempering_c == 0xefc60000), "");62    static_assert((E::tempering_l == 18), "");63    static_assert((E::initialization_multiplier == 1812433253), "");64#if TEST_STD_VER >= 1165    static_assert((E::min() == 0), "");66    static_assert((E::max() == 0xFFFFFFFF), "");67#else68    assert((E::min() == 0));69    assert((E::max() == 0xFFFFFFFF));70#endif71    static_assert((E::default_seed == 5489u), "");72    where(E::word_size);73    where(E::state_size);74    where(E::shift_size);75    where(E::mask_bits);76    where(E::xor_mask);77    where(E::tempering_u);78    where(E::tempering_d);79    where(E::tempering_s);80    where(E::tempering_b);81    where(E::tempering_t);82    where(E::tempering_c);83    where(E::tempering_l);84    where(E::initialization_multiplier);85    where(E::default_seed);86}87 88void89test2()90{91    typedef std::mt19937_64 E;92    static_assert((E::word_size == 64), "");93    static_assert((E::state_size == 312), "");94    static_assert((E::shift_size == 156), "");95    static_assert((E::mask_bits == 31), "");96    static_assert((E::xor_mask == 0xb5026f5aa96619e9ull), "");97    static_assert((E::tempering_u == 29), "");98    static_assert((E::tempering_d == 0x5555555555555555ull), "");99    static_assert((E::tempering_s == 17), "");100    static_assert((E::tempering_b == 0x71d67fffeda60000ull), "");101    static_assert((E::tempering_t == 37), "");102    static_assert((E::tempering_c == 0xfff7eee000000000ull), "");103    static_assert((E::tempering_l == 43), "");104    static_assert((E::initialization_multiplier == 6364136223846793005ull), "");105#if TEST_STD_VER >= 11106    static_assert((E::min() == 0), "");107    static_assert((E::max() == 0xFFFFFFFFFFFFFFFFull), "");108#else109    assert((E::min() == 0));110    assert((E::max() == 0xFFFFFFFFFFFFFFFFull));111#endif112    static_assert((E::default_seed == 5489u), "");113    where(E::word_size);114    where(E::state_size);115    where(E::shift_size);116    where(E::mask_bits);117    where(E::xor_mask);118    where(E::tempering_u);119    where(E::tempering_d);120    where(E::tempering_s);121    where(E::tempering_b);122    where(E::tempering_t);123    where(E::tempering_c);124    where(E::tempering_l);125    where(E::initialization_multiplier);126    where(E::default_seed);127}128 129int main(int, char**)130{131    test1();132    test2();133 134  return 0;135}136