Skip to content

Commit 2b47156

Browse files
authored
Merge pull request #1453 from tinko92/fix/index-content-fp-contract-off
Prevent FP contractions to FMA in index/.../content.hpp to avoid numerical instability in rtree
2 parents 0ba089b + dd01797 commit 2b47156

1 file changed

Lines changed: 18 additions & 0 deletions

File tree

  • include/boost/geometry/index/detail/algorithms

include/boost/geometry/index/detail/algorithms/content.hpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
#ifndef BOOST_GEOMETRY_INDEX_DETAIL_ALGORITHMS_CONTENT_HPP
1717
#define BOOST_GEOMETRY_INDEX_DETAIL_ALGORITHMS_CONTENT_HPP
1818

19+
#include <boost/config.hpp>
20+
1921
#include <boost/geometry/core/access.hpp>
2022
#include <boost/geometry/core/coordinate_dimension.hpp>
2123
#include <boost/geometry/core/coordinate_type.hpp>
@@ -26,6 +28,18 @@
2628

2729
namespace boost { namespace geometry { namespace index { namespace detail {
2830

31+
#if defined(BOOST_GCC)
32+
// The following pragmas set fp-contract=off for GCC, to prevent surprising and
33+
// subtle numerical behaviour changes as a result of cross-statement/function
34+
// FMA contractions which can result in e.g. content(b1) - content(b2) != 0
35+
// (or < 0) for content(b1) == content(b2) (or >=), due to the fp-contract=fast
36+
// default from at least GCC 4.4 to present GCC 15.2. This avoids Github issue
37+
// #1452. Safe to remove after numerically robust handling of degenerate cases
38+
// is ensured at all index::detail::content(box) call sites.
39+
#pragma GCC push_options
40+
#pragma GCC optimize ("fp-contract=off")
41+
#endif
42+
2943
template <typename Indexable>
3044
struct default_content_result
3145
{
@@ -98,6 +112,10 @@ typename default_content_result<Indexable>::type content(Indexable const& b)
98112
>::apply(b);
99113
}
100114

115+
#if defined(BOOST_GCC)
116+
#pragma GCC pop_options
117+
#endif
118+
101119
}}}} // namespace boost::geometry::index::detail
102120

103121
#endif // BOOST_GEOMETRY_INDEX_DETAIL_ALGORITHMS_CONTENT_HPP

0 commit comments

Comments
 (0)