-
-
Notifications
You must be signed in to change notification settings - Fork 1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
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? |
@@ -163,7 +163,7 @@ class LMMS_EXPORT Oscillator | |||
|
|||
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if it would be worth adding a range version for rand
like @rubiefawn did for fastRand
:
Lines 88 to 99 in 3417dfe
template<std::floating_point T> | |
inline auto fastRand(T range) noexcept | |
{ | |
constexpr T FAST_RAND_RATIO = static_cast<T>(1.0 / 32767); | |
return fastRand() * range * FAST_RAND_RATIO; | |
} | |
template<std::floating_point T> | |
inline auto fastRand(T from, T to) noexcept | |
{ | |
return from + fastRand(to - from); | |
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.