Open
Conversation
Depending on the order of includes math.h may be included before we have a chance to set the define
Because we don't control the order of includes and we use M_PI/M_PI_2 in public headers we need to make sure including <cmath> will provide the proper defines.
We already include <cmath>
Contributor
Author
|
The other alternative is to not use |
Not to be confused with the C one that requires math.h.
Contributor
Author
|
BTW, there are C++ variants for these math values, but it requires C++20. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The public headers use
M_PIandM_PI_2which are defined when including<cmath>(ormath.h) and_USE_MATH_DEFINESis defined (and some other defines are possible as well:#if !defined(__STRICT_ANSI__) || defined(_POSIX_C_SOURCE) || defined(_POSIX_SOURCE) || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) || defined(_BSD_SOURCE) || defined(_USE_MATH_DEFINES))In my LLVM 22 toolchain
<string>includes<cmath>. And it's included before the local header in many cases (as well as most toolchain headers are included before the local headers). And even if it was not the case, an app using the public headers could be including<cmath>before including our headers. In that caseM_PIandM_PI_2won't be defined. So we need to make sure_USE_MATH_DEFINESis defined before using our headers.