From 533027ac0c5a7f0de35f2ca314ae71b3582009ec Mon Sep 17 00:00:00 2001 From: assiduous Date: Fri, 10 Apr 2020 20:10:14 -0700 Subject: Using /O2 instead of /Ox optimization on MSVC plus few minor updates to FastRand and tests --- Common/interface/FastRand.hpp | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) (limited to 'Common/interface') diff --git a/Common/interface/FastRand.hpp b/Common/interface/FastRand.hpp index 546da633..da3822c1 100644 --- a/Common/interface/FastRand.hpp +++ b/Common/interface/FastRand.hpp @@ -57,16 +57,16 @@ private: StateType State; }; -/// Generates random real number in [Min, Max] range -template -class FastRandFloat : private FastRand +/// Generates a real random number in [Min, Max] range +template +class FastRandReal : private FastRand { public: - FastRandFloat(FastRand::StateType Seed) noexcept : + FastRandReal(FastRand::StateType Seed) noexcept : FastRand{Seed} {} - FastRandFloat(FastRand::StateType Seed, Type _Min, Type _Max) noexcept : + FastRandReal(FastRand::StateType Seed, Type _Min, Type _Max) noexcept : FastRand{Seed}, Min{_Min}, Range{_Max - _Min} @@ -74,7 +74,7 @@ public: Type operator()() { - return (FastRand::operator()() / static_cast(FastRand::Max)) * Range + Min; + return (static_cast(FastRand::operator()()) / static_cast(FastRand::Max)) * Range + Min; } private: @@ -82,28 +82,30 @@ private: const Type Range = 1.f; }; -/// Generates random integer number in [Min, Max] range -template +using FastRandFloat = FastRandReal; +using FastRandDouble = FastRandReal; + +/// Generates an integer random number in [Min, Max] range class FastRandInt : private FastRand { public: - FastRandInt(FastRand::StateType Seed, Type _Min, Type _Max) noexcept : + FastRandInt(FastRand::StateType Seed, int _Min, int _Max) noexcept : FastRand{Seed}, Min{_Min}, Range{_Max - _Min + 1} { VERIFY_EXPR(_Max > _Min); - VERIFY(Range <= FastRand::Max, "Range is too large"); + VERIFY(Range <= static_cast(FastRand::Max), "Range is too large"); } - Type operator()() + int operator()() { - return Min + static_cast(FastRand::operator()()) % Range; + return Min + static_cast(FastRand::operator()()) % Range; } private: - const Type Min; - const Type Range; + const int Min; + const int Range; }; } // namespace Diligent -- cgit v1.2.3