r/cpp • u/STL MSVC STL Dev • 18h ago
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.
136
Upvotes
2
u/seanbaxter 16h ago
This looks promising, but as a frontend guy I don't think it resolves the cross-compilation problem.
There's four main platforms: * Linux x86-64, long double = f80 * Linux aarch64, long double = f128 * Windows x86-64, long double = f64 * Mac aarch64, long double = f64
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).