r/cpp • u/STL MSVC STL Dev • Sep 10 '26
MSVC C++23: constexpr cmath with LLVM Libc
https://devblogs.microsoft.com/cppblog/msvc-c23-constexpr-cmath-with-llvm-libc/MSVC is shipping C++23 constexpr <cmath> in the next Build Tools update! (And a partial implementation of C++26 constexpr <cmath>.) Our compiler frontend dev Cody Miller will be publishing a series of blog posts about this work, starting with this overview. The next one will be a guest post from LLVM libc's maintainers describing the incredible amount of effort that's gone into their code.
180
Upvotes
23
u/Jovibor_ Sep 11 '26
I have always had a hard time understanding this separation between STDLIB and UCRT.
The
<cmath>header - which is definitely a C++ STL header - has, for some reasons (historical I guess), always been a part of the UCRT.Now, if I've got it all right, we will have two different math machineries: one in the UCRT (the old one), and the new one, based on the LLVM C Library. Correct me if I'm wrong...
Frankly, it's a bit strange, that some parts of the C++ STL are maintained in the separate place (UCRT), not in the main STL repository.
4
u/Aerocatia Sep 11 '26
So what happens if we need C and C++ code to use the same math?
4
u/seanbaxter Sep 11 '26
This looks promising, but as a frontend guy I don't think it resolves the cross-compilation problem.
There's four main platforms:
All the platforms have f64 floating-point math libc. But two of the platforms have exotic long double. If you rely on libm to do the math during constant evaluation, you lose cross-compilation when the target's long double is f80 or f128, and your own target's long double is something else. You need software implementations for the constexpr math functions. It doesn't appear that LLVM C Library provides these.
I think the only path for cross-targeting compilers is MPFR, which is built on GMP (GNU Multi-Precision).
4
u/stablesteady Sep 12 '26
I have been looking forward to this for some time. Great work
1
u/Alastair__ Sep 11 '26
Bit confused by the UCRT in general especially when it comes to static linking.
This issue: https://developercommunity.visualstudio.com/t/SDK-version-change---acos-differences/10999054 seems to be specific to using static linking and SDK version.
4
u/eisenwave WG21 Member Sep 12 '26
You will be happy to hear that with P3935R2: Rebasing
<cmath>on C23, there is a lot more work coming your way :P5
u/misuo Sep 11 '26
So you're not willing to be a monk? ;-) Fair enough. But I thank the "monks" - people who can spend years solving a problem nobody has figured out yet. Our society and scientific progress rely on them.
-5
u/MaitoSnoo [[indeterminate]] Sep 10 '26
so it's slowly sinking in that opensource can be a better choice... clangd instead of IntelliSense wen? 🤔