Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 11 additions & 10 deletions include/pcg_extras.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ operator<<(std::basic_ostream<CharT,Traits>& out, pcg128_t value)
}
if (highpart != 0 || desired_width > 16)
out << highpart;
CharT oldfill;
CharT oldfill = '\0';
if (highpart != 0) {
out.width(16);
oldfill = out.fill('0');
Expand All @@ -156,7 +156,7 @@ operator<<(std::basic_ostream<CharT,Traits>& out, pcg128_t value)
constexpr auto BASE = pcg128_t(10ULL);
do {
auto div = value / BASE;
auto mod = uint32_t(value - (div * BASE));
auto mod = char(value % BASE);
*(--pos) = '0' + mod;
value = div;
} while(value != pcg128_t(0ULL));
Expand Down Expand Up @@ -220,7 +220,7 @@ operator<<(std::basic_ostream<CharT,Traits>&out, uint8_t value)

template <typename CharT, typename Traits>
std::basic_istream<CharT,Traits>&
operator>>(std::basic_istream<CharT,Traits>& in, uint8_t target)
operator>>(std::basic_istream<CharT,Traits>& in, uint8_t& target)
{
uint32_t value = 0xdecea5edU;
in >> value;
Expand Down Expand Up @@ -393,7 +393,7 @@ SrcIter uneven_copy_impl(
constexpr bitcount_t SCALE = SRC_SIZE / DEST_SIZE;

size_t count = 0;
src_t value;
src_t value = 0;

while (dest_first != dest_last) {
if ((count++ % SCALE) == 0)
Expand Down Expand Up @@ -483,10 +483,10 @@ void generate_to_impl(SeedSeq&& generator, DestIter dest,
generator.generate(buffer, buffer+FROM_ELEMS);
uneven_copy(buffer, dest, dest+size);
} else {
uint32_t* buffer = (uint32_t*) malloc(GEN_SIZE * FROM_ELEMS);
uint32_t* buffer = static_cast<uint32_t*>(malloc(GEN_SIZE * FROM_ELEMS));
generator.generate(buffer, buffer+FROM_ELEMS);
uneven_copy(buffer, dest, dest+size);
free(buffer);
free(static_cast<void*>(buffer));
}
}

Expand Down Expand Up @@ -531,13 +531,14 @@ template <typename Iter, typename RandType>
void shuffle(Iter from, Iter to, RandType&& rng)
{
typedef typename std::iterator_traits<Iter>::difference_type delta_t;
typedef typename std::remove_reference<RandType>::type::result_type result_t;
auto count = to - from;
while (count > 1) {
delta_t chosen(bounded_rand(rng, count));
delta_t chosen = delta_t(bounded_rand(rng, result_t(count)));
--count;
--to;
using std::swap;
swap(*(from+chosen), *to);
swap(*(from + chosen), *to);
}
}

Expand Down Expand Up @@ -620,11 +621,11 @@ std::ostream& operator<<(std::ostream& out, printable_typename<T>) {
const char *implementation_typename = typeid(T).name();
#ifdef __GNUC__
int status;
const char* pretty_name =
char* pretty_name =
abi::__cxa_demangle(implementation_typename, NULL, NULL, &status);
if (status == 0)
out << pretty_name;
free((void*) pretty_name);
free(static_cast<void*>(pretty_name));
if (status == 0)
return out;
#endif
Expand Down
13 changes: 9 additions & 4 deletions include/pcg_random.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,15 @@
#ifndef PCG_RAND_HPP_INCLUDED
#define PCG_RAND_HPP_INCLUDED 1

#include <algorithm>
#include <cinttypes>
#include <cstddef>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <limits>
#include <iostream>
#include <iterator>
#include <type_traits>
#include <utility>
#include <locale>
Expand Down Expand Up @@ -321,7 +323,7 @@ class specific_stream {
specific_stream() = default;

specific_stream(itype specific_seq)
: inc_((specific_seq << 1) | itype(1U))
: inc_(itype(specific_seq << 1) | itype(1U))
{
// Nothing (else) to do.
}
Expand Down Expand Up @@ -380,7 +382,7 @@ class engine : protected output_mixin,

static constexpr result_type max()
{
return ~result_type(0UL);
return result_type(~result_type(0UL));
}

protected:
Expand Down Expand Up @@ -422,7 +424,7 @@ class engine : protected output_mixin,
static itype distance(itype cur_state, itype newstate, itype cur_mult,
itype cur_plus, itype mask = ~itype(0U));

itype distance(itype newstate, itype mask = ~itype(0U)) const
itype distance(itype newstate, itype mask = itype(~itype(0U))) const
{
return distance(state_, newstate, multiplier(), increment(), mask);
}
Expand Down Expand Up @@ -1360,7 +1362,10 @@ bool operator==(const extended<table_pow2, advance_pow2,
auto& base_lhs = static_cast<const baseclass&>(lhs);
auto& base_rhs = static_cast<const baseclass&>(rhs);
return base_lhs == base_rhs
&& !memcmp((void*) lhs.data_, (void*) rhs.data_, sizeof(lhs.data_));
&& !std::equal(
std::begin(lhs.data_), std::end(lhs.data_),
std::begin(rhs.data_)
);
}

template <bitcount_t table_pow2, bitcount_t advance_pow2,
Expand Down
11 changes: 10 additions & 1 deletion test-high/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,16 @@ TARGETS = \
check-pcg64_oneseq check-pcg64_oneseq_once_insecure check-pcg64_unique \
check-pcg128_once_insecure check-pcg128_oneseq_once_insecure

CPPFLAGS += -I../include
# special flags for some compilers
CPPFLAGS_clang++ += \
-Weverything \
-Wno-c++98-compat \
-Wno-c++98-compat-pedantic \
-Wno-date-time \
-Wno-undef \
-Wno-unused-macros

CPPFLAGS += -I../include -Wall -Wextra $(CPPFLAGS_$(CXX))
CXXFLAGS += -std=c++11
CC = $(CXX) # Cheat so that linking uses the C++ compiler

Expand Down
1 change: 0 additions & 1 deletion test-high/pcg-test-noadvance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,6 @@ int main(int argc, char** argv)
cout << (rng(2) ? "H" : "T");
cout << endl;

RNG rng_copy{rng};
/* Roll some dice */
printf(" Rolls:");
for (int i = 0; i < 33; ++i)
Expand Down