Use std::formatted_size() instead of numDigitsAsInt()#8321
Use std::formatted_size() instead of numDigitsAsInt()#8321rubiefawn wants to merge 1 commit intoLMMS:masterfrom
std::formatted_size() instead of numDigitsAsInt()#8321Conversation
Resolves a TODO in lmms_math.h by removing numDigitsAsInt() and using std::formatted_size() instead. This also removes MathTest.cpp, since its only purpose was to test the now removed numDigitsAsInt().
|
Looks like I'm less sure what's going on with Apple Clang. According to their own docs, I am not familiar with Xcode, so I'm not sure what to look for, but I do wonder if these parts of the logs are related and relevant: Does this mean |
Yeah, this will require GCC 13.
No, that PR only updates the 3rd party libraries, not the compiler. Unfortunately, AppImages have a minimum glibc version which depends on the GCC compiler version used to build it, so upgrading the Linux x86_64 build runner to Ubuntu 24.04 (which has GCC 13) would also bump the minimum glibc version to 2.39. Because we want the AppImage to be usable on as many distros as possible, we are forced to use an older GCC compiler. In #8105, we've been exploring a new AppImage runtime which would fix this issue, but it's not ready yet.
Yes, unfortunately the XCode documentation says the minimum deployment target for |
Ah, I saw "20.04 -> 22.04" and thought "Maybe that has the new GCC version, won't check tho" lol. Good to know. Oh, I also misinterpreted So I guess I just let this PR age for a decade, until an OS from 2022 starts to feel like a reasonable minimum supported version? 💀 |
With a single exception, which is already handled by LMMS#8321
With a single exception, which is already handled by LMMS#8321
With a single exception, which is already handled by LMMS#8321
|
The PR looks technically good. Though one note: Luckily, this is just one CPP file affected here. Nonetheless, compile time will increase. I wonder though what our general approach is when it comes to using STL, it seems wrong to just discuss this in one single PR. |
Resolves a TODO in
lmms_math.hby removingnumDigitsAsInt()and usingstd::formatted_size()instead. Also removesMathTest.cpp, since its only purpose was to test the now removednumDigitsAsInt().inb4
"Why not just update
numDigitsAsInt()to usestd::formatted_size()internally?"numDigitsAsInt()accepts afloat, rounds it, casts it to anint, and then calculates the number of digits of thatint. The implied use is for cases where a value intended to be an integer is stored as a floating-point value instead. This implicit casting is a communication mistake, and I can imagine a future where somebody tries to use this function by casting theirintto afloatin order to pass it in. Yuck.Better to use
std::formatted_size()and make the casting explicit at the callsite so that this oddity of storing an integer value in afloatis obvious.Testing
The only place
numDigitsAsInt()was used was inLv2ViewBase.cpp(it seems that pretty much all other LCD spinboxes have hard-coded digit counts) so for testing just load up an LV2 plugin with an integer parameter and make sure it looks identical on this branch vsmaster.That said, I'm not sure how much testing is required, given the following short test program passes:
Show test program source
If that unit test from
MathTest.cppwas enough to demonstrate thatnumDigitsAsInt()was working properly, then perhaps it is enough to show thatstd::formatted_size()is as well.