This patch fixes the following clang compiler error:
crc/../arch/../lib/rand.h:109:25: error: implicit conversion from
'unsigned long long' to 'double' changes value from
18446744073709551615
to
18446744073709551616 [-Werror,-Wimplicit-int-float-conversion]
return (val + 1.0) / (FRAND64_MAX + 1.0);
^~~~~~~~~~~ ~
crc/../arch/../lib/rand.h:9:22: note: expanded from macro 'FRAND64_MAX'
#define FRAND64_MAX (-1ULL)
^~~~~
Fixes:
e7b240474543 ("Fixups for poisson rate")
Signed-off-by: Bart Van Assche <bvanassche@acm.org>
#include "types.h"
#define FRAND32_MAX (-1U)
#include "types.h"
#define FRAND32_MAX (-1U)
+#define FRAND32_MAX_PLUS_ONE (1.0 * (1ULL << 32))
#define FRAND64_MAX (-1ULL)
#define FRAND64_MAX (-1ULL)
+#define FRAND64_MAX_PLUS_ONE (1.0 * (1ULL << 32) * (1ULL << 32))
struct taus88_state {
unsigned int s1, s2, s3;
struct taus88_state {
unsigned int s1, s2, s3;
if (state->use64) {
uint64_t val = __rand64(&state->state64);
if (state->use64) {
uint64_t val = __rand64(&state->state64);
- return (val + 1.0) / (FRAND64_MAX + 1.0);
+ return (val + 1.0) / FRAND64_MAX_PLUS_ONE;
} else {
uint32_t val = __rand32(&state->state32);
} else {
uint32_t val = __rand32(&state->state32);
- return (val + 1.0) / (FRAND32_MAX + 1.0);
+ return (val + 1.0) / FRAND32_MAX_PLUS_ONE;
r = __rand32(&state->state32);
end++;
r = __rand32(&state->state32);
end++;
- return (int) ((double)end * (r / (FRAND32_MAX + 1.0)));
+ return (int) ((double)end * (r / FRAND32_MAX_PLUS_ONE));
}
static inline uint64_t rand64_upto(struct frand_state *state, uint64_t end)
}
static inline uint64_t rand64_upto(struct frand_state *state, uint64_t end)
r = __rand64(&state->state64);
end++;
r = __rand64(&state->state64);
end++;
- return (uint64_t) ((double)end * (r / (FRAND64_MAX + 1.0)));
+ return (uint64_t) ((double)end * (r / FRAND64_MAX_PLUS_ONE));