Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid M_PI #1553

Closed
bernhardmgruber opened this issue Dec 25, 2021 · 7 comments · Fixed by #1710
Closed

Avoid M_PI #1553

bernhardmgruber opened this issue Dec 25, 2021 · 7 comments · Fixed by #1710

Comments

@bernhardmgruber
Copy link
Member

alpaka/rand/RandDefault.hpp uses M_PI which is a non-standard extension. Please replace the constant by e.g. boost::math::constants::pi.

bernhardmgruber added a commit to bernhardmgruber/alpaka that referenced this issue Dec 25, 2021
@fwyzard
Copy link
Contributor

fwyzard commented Dec 26, 2021

Out of curiosity, which C library does not define M_PI ?

@bernhardmgruber
Copy link
Member Author

I primarily encountered it with MSVC 19.30 (VS 2022), where you need to explicitely ask for it with _USE_MATH_DEFINES before including <cmath>. For some reason we did not have that problem in the CI with VS 2019.

@j-stephan
Copy link
Member

It sounds less intrusive to define another preprocessor flag rather than add yet another Boost dependency (see #481).

@sbastrakov
Copy link
Member

An own variable template for pi is also an option i think. No ugly all caps name as a bonus

@bernhardmgruber
Copy link
Member Author

It sounds less intrusive to define another preprocessor flag rather than add yet another Boost dependency (see #481).

We already have a Boost dependency. There is no way around it. So why reinvent the wheel?
Plus: C++20 has std::numbers::pi<T>.

IMO the preprocessor flag adds more complexity, since it complicates the build system. And I think we have users, that don't use alpaka's CMake, so they would need to specify the flag manually each time.

@j-stephan
Copy link
Member

j-stephan commented Jan 5, 2022

We already have a Boost dependency. There is no way around it. So why reinvent the wheel?

What are we reinventing? _USE_MATH_DEFINES is the official MSVC way: https://docs.microsoft.com/en-us/cpp/c-runtime-library/math-constants?view=msvc-170

Plus: C++20 has std::numbers::pi.

Then we can switch to that once C++20 is available to us.

IMO the preprocessor flag adds more complexity, since it complicates the build system.

It is literally a one-liner in CMake. And we need to change the build system in Boost's case as well since we would need to check for the existence of boost::math and link to it (even more lines!).

And I think we have users, that don't use alpaka's CMake, so they would need to specify the flag manually each time.

Those don't use MSVC anyway AFAIK.

@fwyzard
Copy link
Contributor

fwyzard commented Jan 5, 2022

And I think we have users, that don't use alpaka's CMake, so they would need to specify the flag manually each time.

Those don't use MSVC anyway AFAIK.

We don't use CMake, and we don't use MSVC, and have been using M_PI since... (checks)... well, technically "since ever" as far as CMSSW is concerned: the first (pre)release from 2005 was already using it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants