Skip to content

Gecode 7: native float interval instead of Boost - #291

Draft
zayenz wants to merge 5 commits into
feature/breaking-7-07-modern-classesfrom
feature/breaking-7-08-native-interval
Draft

zayenz wants to merge 5 commits into
feature/breaking-7-07-modern-classesfrom
feature/breaking-7-08-native-interval

Conversation

@zayenz

@zayenz zayenz commented Nov 20, 2026 •

Copy link
Copy Markdown
Member

Gecode has long vendored a copy of Boost.Interval under gecode/third-party just to back FloatVal. This PR replaces it with Gecode's own Float::Interval, removing the vendored Boost dependency and headers completely.

The work is split into five commits so the rounding fix, the new implementation, the switchover, and the Boost removal can each be reviewed on its own:

  • Directed rounding is first made sound under compiler optimization. Previously, optimizers could fold constants in round-to-nearest, share one square root or quotient across both bounds, or fuse a negated multiplication, returning a bound on the wrong side of the exact result (even in Clang Debug builds). Operands and results now pass through an optimization barrier (an empty volatile asm on GCC and Clang, and a volatile store/reload elsewhere), so neither Gecode nor applications need special floating-point compiler flags. Integer rounding uses floor and ceil, and the even-root bounds in pow and nroot go through the same rounding helpers.
  • Float::Interval (gecode/float/interval.hpp) is added beside the Boost copy, implementing every interval operation FloatVal needs in Gecode style with outward rounding through Float::RoundingBase. Temporary differential tests verify that every operation matches Boost bit for bit.
  • FloatVal switches to storing Float::Interval, and Float::RoundingBase and Float::Rounding become Gecode classes using <cfenv> (or _control87 on MSVC x86/x64). Rounding is a non-copyable RAII scope that saves and restores the caller's rounding mode. FloatVal and Float::ScaleView also become trivially copyable, removing the last entry from AllowedTypes in the value-parameter check (though FloatVal stays passed by const& by convention).
  • gecode/third-party, the temporary differential tests, and the installed Boost headers and LICENSE_1_0.txt are removed.
  • changelog.in records the new native library, the API changes to Float::RoundingBase, Float::Rounding, and FloatValImpType, and the ABI note for the two exported functions taking FloatVal by value.

Testing

Tested before the stack split on arm64 macOS:

  • The full float test suite (including sweeps) passes in Release and Debug, both with and without MPFR.
  • The directed-rounding probe is exact with AppleClang, LLVM 22, and GCC 14 at -O0, -O2, and -O3.
  • All four float examples produce the same solutions and search statistics as before the switch.

Because MSVC cannot be built locally, Windows CI is the only place the _control87 and per-operation rounding paths execute. Those jobs passed on the earlier unified version of #274.

Stack

Merge in this order. #242 targets main, and each later PR builds on the one before it so its diff shows only its own commits. The first four PRs are standalone search and random-number changes; #284 through #274 are the Gecode 7 changes split out of what used to be a single branch.

  1. Rank solutions with Space::compare in best-solution search #242 Rank solutions with Space::compare
  2. Rename the meta-search hooks to hub and spoke #282 Rename the meta-search hooks to hub and spoke
  3. Give meta search hub and spoke contexts and report why search ended #283 Hub and spoke contexts and end reasons
  4. Add extensible random generators with reproducible stream splitting #241 Splittable random generators
  5. Gecode 7: CMake-only C++23 build baseline #284 Gecode 7: build baseline
  6. Gecode 7: format the sources with LLVM 22 #285 Gecode 7: reformat
  7. Gecode 7: normalized API names, LT constants and Clang checks #286 Gecode 7: API names, LT constants, checks
  8. Gecode 7: post nothing for empty arrays #287 Gecode 7: empty arrays
  9. Gecode 7: pass large parameters by const reference #288 Gecode 7: const& parameters
  10. Gecode 7: state and assert the heap size contract #289 Gecode 7: heap contract
  11. Gecode 7: trivially copyable handles and defaulted special members #290 Gecode 7: modern classes
  12. Gecode 7: native float interval instead of Boost #291 Gecode 7: native float interval ← this PR
  13. Gecode 7: bug fixes and Doxygen warnings #292 Gecode 7: bug fixes and Doxygen
  14. Gecode 7: scoped enums and descriptive constant names #293 Gecode 7: scoped enums
  15. Gecode 7: clang-tidy sweep #274 Gecode 7: clang-tidy sweep

Zdev-Change-Id: Z5c93bdc69344351025efb0691a336874ba0c83aa9d6f22ccd43c8899bdd6ce83
Float::Interval in gecode/float/interval.hpp provides every interval operation FloatVal uses, written in Gecode style from the mathematics of each operation and licensed like the rest of Gecode. Each public operation opens one Float::Rounding and rounds through RoundingBase, so boost-006's barriers still apply. FloatVal does not use it yet. Focused tests cover outward rounding, singleton and empty intervals, and the comparison truth table; a temporary differential test checks that every result matches the vendored Boost interval bit for bit until the copy is removed.

Zdev-Change-Id: Zf4ce2c26dcc990c3af6acc8d9e1ef911f4d24d5a52a56ec414b369a1284d1ec7
FloatVal now stores Float::Interval, and Float::RoundingBase and Float::Rounding are Gecode classes. The rounding mode is read and set with <cfenv>, or with _control87 for MSVC on x86 and x64. Rounding is a scope that saves the caller's mode and restores it, and it cannot be copied. FloatVal's public operations are unchanged, its comparisons call the native certainly-relations, and it is now trivially copyable. No float header includes Boost any more; the Boost copy stays only for the temporary differential test, which now checks FloatVal against it.

Zdev-Change-Id: Zb0421a288f748b79528fe4e547c738571dac5eb690ffaa00dc5b799f9c222a1c
gecode/third-party and the temporary differential test are gone, together with every reference in the build, checks, Doxygen configuration, and documentation. Gecode no longer installs Boost headers or LICENSE_1_0.txt. Float::ScaleView is now trivially copyable like FloatVal, so the value-parameter check needs no allowed types; FloatVal is still passed by const& by convention.

Zdev-Change-Id: Z93535760ded6e8a1ccd7d757347f7ece740feaa173116d8fc9850bde12deb770
The 7.0.0 entries describe Gecode's own Float::Interval and the removed Boost copy, the API changes of Float::RoundingBase, Float::Rounding, and FloatValImpType, and the trivially copyable FloatVal, whose by-value calling convention changes for the two exported functions that take it by value.

Zdev-Change-Id: Zfb4cd384cd9b0d57890f4ecef2c4ec0803d04137d6a43586a4990458f0cc0537

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant