Browse Source

Fixed an edge case in Random::nextFloat() for dividends approaching std::numeric_limits<uint32>::max()

tags/2021-05-28
ed 5 years ago
parent
commit
77aff4658b
1 changed files with 2 additions and 1 deletions
  1. +2
    -1
      modules/juce_core/maths/juce_Random.cpp

+ 2
- 1
modules/juce_core/maths/juce_Random.cpp View File

@@ -105,7 +105,8 @@ bool Random::nextBool() noexcept
float Random::nextFloat() noexcept
{
return static_cast<uint32> (nextInt()) / (std::numeric_limits<uint32>::max() + 1.0f);
auto result = static_cast<uint32> (nextInt()) / (std::numeric_limits<uint32>::max() + 1.0f);
return result == 1.0f ? 1.0f - std::numeric_limits<float>::epsilon() : result;
}
double Random::nextDouble() noexcept


Loading…
Cancel
Save