Fix clang warning due to implicit conversion from int to float for the RAND_MAX macro#7717
Conversation
|
It seems You have fixed not all such warnings: P.S. |
|
@firewall1110 thanks for the catches. I just noted the one case which was giving me trouble. I'll fix the rest later, but I'll take some time off so can't really say when. |
|
@firewall1110 can you check again? |
Ahh yes, now i remember. I was using clang for iwyu which is when i saw these warnings. After that, I was on gcc, and thought the warnings disappeared. |
After ~5 h - now I about to go to rehearsal with vocal ensemble ... |
|
There is no more RAND_MAX related warnings. P.S. Compilation stderr: Used build script: Invocation command: |
|
@firewall1110 you fine if i get done with just the RAND_MAX warnings. I'll look at the other warnings seperately. |
File in P.S. is only for complete information, all others warnings should not be fixed here. [Edited:] You respect me too much (Thank You for this, but ... ) |
|
@sakertooth @messmerd can i get one approval and get this merged real quick? |
| static inline sample_t noiseSample( const float ) | ||
| { | ||
| return 1.0f - rand() * 2.0f / RAND_MAX; | ||
| return 1.0f - rand() * 2.0f / static_cast<float>(RAND_MAX); |
There was a problem hiding this comment.
I wonder if it would be worth adding a range version for rand like @rubiefawn did for fastRand:
Lines 88 to 99 in 3417dfe
There was a problem hiding this comment.
That might make sense too, but I am focusing more on #7677 rn so this has to wait a bit, if i'm refactoring
There was a problem hiding this comment.
There's a lot of places in the code where rand()/std::rand() is used in this way, which we may want to change to just use fastRand(). I would argue that belongs in a separate PR since it is beyond the scope of "fix compiler warnings".
Edit: See #7741
A minor warning, and a minor fix. RAND_MAX is an integer macro, which seems to introduce a warning when divided.