summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBart Van Assche <bvanassche@acm.org>2020-06-21 19:01:00 -0700
committerBart Van Assche <bvanassche@acm.org>2020-06-21 19:19:19 -0700
commitaf3e7a8f487ae347001d1bd229ab274d1d4ab92d (patch)
tree82e39e9b2b6e2c6765decf0f3d72acbfe2e87259
parent5ad910123aafa0254f67291b3314f4439a6a8736 (diff)
downloadfio-af3e7a8f487ae347001d1bd229ab274d1d4ab92d.tar.gz
fio-af3e7a8f487ae347001d1bd229ab274d1d4ab92d.tar.bz2
Make __rand_0_1() compatible with clang
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>
-rw-r--r--lib/rand.h10
1 files changed, 6 insertions, 4 deletions
diff --git a/lib/rand.h b/lib/rand.h
index 2ccc1b37..46c1c5e0 100644
--- a/lib/rand.h
+++ b/lib/rand.h
@@ -6,7 +6,9 @@
#include "types.h"
#define FRAND32_MAX (-1U)
+#define FRAND32_MAX_PLUS_ONE (1.0 * (1ULL << 32))
#define FRAND64_MAX (-1ULL)
+#define FRAND64_MAX_PLUS_ONE (1.0 * (1ULL << 32) * (1ULL << 32))
struct taus88_state {
unsigned int s1, s2, s3;
@@ -106,11 +108,11 @@ static inline double __rand_0_1(struct frand_state *state)
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);
- return (val + 1.0) / (FRAND32_MAX + 1.0);
+ return (val + 1.0) / FRAND32_MAX_PLUS_ONE;
}
}
@@ -122,7 +124,7 @@ static inline uint32_t rand32_upto(struct frand_state *state, uint32_t 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)
@@ -133,7 +135,7 @@ static inline uint64_t rand64_upto(struct frand_state *state, uint64_t 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));
}
/*