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
View all comments
Show parent comment
6
u/STL MSVC STL Dev Sep 11 '26
The static UCRT is provided by the WinSDK, which is why things can be dependent on the SDK version. (Same for the debug DLL. Only the release DLL is part of the OS.)
Looks like you're also seeing x64 vs. x86 implementation variation (this can happen due to usage of FMA or a million other reasons). This is precisely the sort of insanity that Cody's
/Zc:cmathtechnique avoids; with that option,<cmath>'s inclusion of<math.h>is intercepted by the compiler and rewritten so that instead of old UCRTmath.h, an STL-internal header is picked up (__msvc_math.hppbut you should not include it directly), and it will send functions to LLVM libc (when implemented by them), which will return mathematically accurate, correctly rounded results regardless of platform, OS version, or SDK version.