From a032f771afedd3cfaccad7f5da02bc615ac9e871 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=BCnter=20Obiltschnig?= Date: Fri, 5 Nov 2021 14:58:40 +0100 Subject: [PATCH] #2823: error: implicit conversion from 'int' to 'float' changes value from 2147483647 to 2147483648 --- Foundation/include/Poco/Random.h | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/Foundation/include/Poco/Random.h b/Foundation/include/Poco/Random.h index 3db078e13..46d97b8ec 100644 --- a/Foundation/include/Poco/Random.h +++ b/Foundation/include/Poco/Random.h @@ -14,7 +14,7 @@ // // // Based on the FreeBSD random number generator. -// src/lib/libc/stdlib/random.c,v 1.25 +// src/lib/libc/stdlib/random.c,v 1.25 // // Copyright (c) 1983, 1993 // The Regents of the University of California. All rights reserved. @@ -91,16 +91,16 @@ public: UInt32 next(UInt32 n); /// Returns the next 31-bit pseudo random number modulo n. - + char nextChar(); /// Returns the next pseudo random character. - + bool nextBool(); /// Returns the next boolean pseudo random value. - + float nextFloat(); /// Returns the next float pseudo random number between 0.0 and 1.0. - + double nextDouble(); /// Returns the next double pseudo random number between 0.0 and 1.0. @@ -146,16 +146,16 @@ inline bool Random::nextBool() return (next() & 0x1000) != 0; } - + inline float Random::nextFloat() { - return float(next()) / 0x7FFFFFFF; + return static_cast(nextDouble()); } - + inline double Random::nextDouble() { - return double(next()) / 0x7FFFFFFF; + return static_cast(next()) / static_cast(0x7FFFFFFF); }