-
-
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
Use C++20 std::numbers, std::lerp() #7696
base: master
Are you sure you want to change the base?
Conversation
Also replace the only use of lmms::numbers::inv_e with a local constexpr instead
They were only used in one or two places each
This is probably not needed for some of these files. I'll remove those later
Rest in peace lmms::numbers::tau, my beloved
A lot of the remaining constants in lmms_constants.h are specific to SaProcessor. If they are only used there, shouldn't they be in SaProcessor.h?
Almost all the remaining constants in Besides moving Edit: |
- And also move F_EPSILON into lmms_math.h - And also add an overload for fast_rand() to specify a higher and lower bound - And a bunch of other nonsense
As well as time travel to undo several foolish decisions and squash tiny commits together
a254925
to
d7a735b
Compare
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.
Looks pretty good. I just have a few suggestions
include/lmms_constants.h
Outdated
inline constexpr std::integral auto MaxScaleCount = 10; //!< number of scales per project | ||
inline constexpr std::integral auto MaxKeymapCount = 10; //!< number of keyboard mappings per project |
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 no need for concepts here
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.
In your opinion, when would concepts be needed? I'd like to better understand when I should or should not be using these; they seem like a reasonable default to me with my limited understanding of C++.
include/lmms_math.h
Outdated
namespace | ||
{ | ||
|
||
inline constexpr float F_EPSILON = 1.0e-10f; // 10^-10 | ||
|
||
} |
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.
Anonymous namespaces shouldn't be in headers.
I think this would be fine just in the lmms
namespace.
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.
Anonymous namespaces shouldn't be in headers.
Why is this? (Genuinely curious, I wouldn't know)
I think this would be fine just in the lmms namespace.
It's only used for approximatelyEqual()
and roundAt()
so I figured making it not visible outside this header would be appropriate. I can go ahead and move it back into lmms_constants.h
if you believe it should be publicly available.
include/lmms_math.h
Outdated
template<std::floating_point T = float> | ||
inline T fast_rand(T range) noexcept |
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.
Would the = float
prevent it from deducing the type from the argument?
I think I'd prefer the fastRand
name for this function and its overloads, for consistency.
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.
= float
just provides a default value to the template if none are manually provided, unless I am mistaken. (Edit: So yes, it does prevent inference, but it does allow double
to be used if manually specified)
I'll go ahead and update the fast_rand()
s to fastRand()
.
template<std::floating_point T = float> | ||
inline auto fastPow10f(T x) |
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.
Could this be inline auto fastPow10f(std::floating_point auto x)
instead?
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.
The T
is used to select the std::numbers::ln10_v<T>
of the same type as the input parameter. Is there a way to do that while applying your suggestion?
#include "interpolation.h" | ||
#include "lmms_math.h" |
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.
Is lmms_math.h still needed?
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.
SlicerT uses sign()
on line 187:
if (sign(lastValue) != sign(singleChannel[i]))
Prior to this PR, interpolation.h
used to include lmms_math.h
, so it was being indirectly included.
Co-authored-by: Dalton Messmer <[email protected]>
Co-authored-by: Dalton Messmer <[email protected]>
In #7558, I added
lmms::numbers
; in this PR, I destroy it.<concepts>
such asfloating_point
rather thantypename
for templateslmms::numbers
that are also defined instd::numbers
with thestd::numbers
versionlmms::numbers::tau
with2 * std::numbers::pi
? (I love τ dearly, but @messmerd has a point)lerp()
fromlmms_math.h
andlinearInterpolate()
frominterpolation.h
withstd::lerp()
(this should have happened in Update math functions to C++ standard library #7685 but I didn't realizestd::lerp()
existed)