Skip to content

math: compile FP-free with BND_MATH_NO_FP (incl. the single header)#5

Merged
NiceAndPeter merged 1 commit into
mainfrom
math-nofp-guard
Jun 21, 2026
Merged

math: compile FP-free with BND_MATH_NO_FP (incl. the single header)#5
NiceAndPeter merged 1 commit into
mainfrom
math-nofp-guard

Conversation

@NiceAndPeter

Copy link
Copy Markdown
Owner

Phase 2 of the math-engine plan — the FP-free guard

Lets the library (and the single header) compile with no hardware floating point and no <cmath>, leaving the always-present integer/CORDIC engine to serve the full bnd::math API. The public surface, output grids, and types are unchanged — only the compute backend differs.

What BND_MATH_NO_FP does

  • Compiles the double (FP) engine and its #include <cmath> out entirely.
  • Implied by BND_MATH_FIXED; auto-enabled when __STDC_HOSTED__ == 0 (-ffreestanding).
  • All transcendentals are constexpr under it (the integer engine).

How it works

  • cmath_double.hpp resolves the macro and gates <cmath> + the whole dbl engine behind #ifndef BND_MATH_NO_FP. The guard is at conditional depth, so the amalgamator keeps the <cmath> include inline under the same guard — the single header honors the FP-free path identically to the modular headers (no longer hoisted unconditionally to the top).
  • Dispatch and the constexpr BND_MATH_FN macro in cmath.hpp key on BND_MATH_NO_FP. Every dbl:: reference already sat in an #else branch, so the integer engine is selected cleanly.

Proof (not just "it compiles")

New single_header_nofp_smoke target + Linux CI step compiles the single header with -DBND_MATH_NO_FP and a poison <cmath> shim first on the include path — the build hard-errors if any <cmath> is pulled in. Confirmed locally that it fires without the macro (genuine) and passes with it.

Verification

  • default engine 397/397, CORDIC engine 440/440
  • single_header_nofp_smoke builds & runs FP-free; single_header_smoke / single_header_freestanding_smoke still build
  • amalgamation regenerated; amalgamate_up_to_date green

🤖 Generated with Claude Code

Add BND_MATH_NO_FP: when set, the double (FP) engine and its <cmath> include
compile out entirely, leaving the always-present integer/CORDIC engine to serve
the full bnd::math API. The public surface, output grids, and types are
unchanged — only the compute backend differs. Implied by BND_MATH_FIXED and
auto-enabled on freestanding targets (__STDC_HOSTED__ == 0).

- cmath_double.hpp resolves BND_MATH_NO_FP and gates <cmath> + the entire dbl
  engine behind it. The guard is at conditional depth, so the amalgamator keeps
  the <cmath> include inline under the same #ifndef — the SINGLE HEADER honors
  the FP-free path identically to the modular headers.
- cmath.hpp dispatch and the constexpr BND_MATH_FN macro key on BND_MATH_NO_FP
  (every dbl:: reference already sat in the #else branch), so the integer engine
  is selected and constexpr whenever FP is unavailable.
- New single_header_nofp_smoke target + CI step (Linux): compiles the single
  header with BND_MATH_NO_FP and a poison <cmath> shim placed first on the
  include path, so the build hard-errors if any <cmath> is pulled in. Verified it
  fires without the macro (genuine proof) and passes with it.
- docs/math.md: document the FP-free build.

Verified: default 397/397, CORDIC 440/440, nofp smoke builds+runs FP-free.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@NiceAndPeter NiceAndPeter merged commit f79a9f1 into main Jun 21, 2026
16 checks passed
@NiceAndPeter NiceAndPeter deleted the math-nofp-guard branch June 21, 2026 17:58
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