From 852f92780c9c82dae7f5fbcfff91165510719f90 Mon Sep 17 00:00:00 2001 From: Satoshi Misumi <18492524+lzpel@users.noreply.github.com> Date: Wed, 22 Jul 2026 00:45:41 +0900 Subject: [PATCH] Fix M_PI being unavailable where _USE_MATH_DEFINES comes too late (#4023) Co-authored-by: Paul Romano --- examples/custom_source/source_ring.cpp | 1 + .../parameterized_source_ring.cpp | 1 + src/external/quartic_solver.cpp | 2 +- src/mesh.cpp | 13 ++++++------- src/plot.cpp | 3 +-- 5 files changed, 10 insertions(+), 10 deletions(-) diff --git a/examples/custom_source/source_ring.cpp b/examples/custom_source/source_ring.cpp index 5ab531a4a..bce6c27eb 100644 --- a/examples/custom_source/source_ring.cpp +++ b/examples/custom_source/source_ring.cpp @@ -1,3 +1,4 @@ +#define _USE_MATH_DEFINES #include // for M_PI #include // for unique_ptr diff --git a/examples/parameterized_custom_source/parameterized_source_ring.cpp b/examples/parameterized_custom_source/parameterized_source_ring.cpp index 9756e1b97..3aabf3581 100644 --- a/examples/parameterized_custom_source/parameterized_source_ring.cpp +++ b/examples/parameterized_custom_source/parameterized_source_ring.cpp @@ -1,3 +1,4 @@ +#define _USE_MATH_DEFINES #include #include #include diff --git a/src/external/quartic_solver.cpp b/src/external/quartic_solver.cpp index 915020ffa..71bdb25c3 100644 --- a/src/external/quartic_solver.cpp +++ b/src/external/quartic_solver.cpp @@ -1,5 +1,5 @@ -#include #define _USE_MATH_DEFINES // to make M_PI declared in Intel and MSVC compilers +#include #include #include #include diff --git a/src/mesh.cpp b/src/mesh.cpp index 89d1ff24b..b05560d2a 100644 --- a/src/mesh.cpp +++ b/src/mesh.cpp @@ -1,11 +1,10 @@ #include "openmc/mesh.h" #include // for copy, equal, min, min_element #include -#include // for uint64_t -#include // for memcpy -#define _USE_MATH_DEFINES // to make M_PI declared in Intel and MSVC compilers -#include // for ceil -#include // for size_t +#include // for ceil +#include // for size_t +#include // for uint64_t +#include // for memcpy #include #include // for accumulate #include @@ -1829,7 +1828,7 @@ StructuredMesh::MeshIndex CylindricalMesh::get_indices( } else { mapped_r[1] = std::atan2(r.y, r.x); if (mapped_r[1] < 0) - mapped_r[1] += 2 * M_PI; + mapped_r[1] += 2 * PI; } MeshIndex idx = StructuredMesh::get_indices(mapped_r, in_mesh); @@ -2123,7 +2122,7 @@ StructuredMesh::MeshIndex SphericalMesh::get_indices( mapped_r[1] = std::acos(r.z / mapped_r.x); mapped_r[2] = std::atan2(r.y, r.x); if (mapped_r[2] < 0) - mapped_r[2] += 2 * M_PI; + mapped_r[2] += 2 * PI; } MeshIndex idx = StructuredMesh::get_indices(mapped_r, in_mesh); diff --git a/src/plot.cpp b/src/plot.cpp index 96df1c5be..5c4eb9460 100644 --- a/src/plot.cpp +++ b/src/plot.cpp @@ -1,7 +1,6 @@ #include "openmc/plot.h" #include -#define _USE_MATH_DEFINES // to make M_PI declared in Intel and MSVC compilers #include #include #include @@ -1328,7 +1327,7 @@ std::pair RayTracePlot::get_pixel_ray( int horiz, int vert) const { // Compute field of view in radians - constexpr double DEGREE_TO_RADIAN = M_PI / 180.0; + constexpr double DEGREE_TO_RADIAN = PI / 180.0; double horiz_fov_radians = horizontal_field_of_view_ * DEGREE_TO_RADIAN; double p0 = static_cast(pixels()[0]); double p1 = static_cast(pixels()[1]);