Skip to content

feat(takum): full constexpr support across all operators #741

@Ravenwater

Description

@Ravenwater

Goal

Bring takum (takum logarithmic encoding) to fully constexpr across all user-facing operators (construction, arithmetic, comparison, conversion). Part of the umbrella effort tracked in #723 to make every Universal number system constexpr-compliant for true plug-in semantics with native arithmetic types.

Like lns, takum needs a constexpr log2() for IEEE-754 construction. Hard prerequisite is #423.

Why

Constexpr arithmetic on a drop-in numeric type unlocks: compile-time coefficient tables (DSP, ML, scientific computing), static_assert numerical-bound checks, constinit constants for embedded targets, constant folding at low optimization levels, and drop-in parity with native int/float/double in any constexpr context.

Scope

  1. Audit: walk include/sw/universal/number/takum/ and inventory every operator's current constexpr status.
  2. Construction: integer, float, double (and long double where supported) literals must work in constexpr context. Replace std::frexp/std::isnan/std::isinf with extractFields + raw-exponent checks where applicable (proven pattern from feat(posit): enable constexpr IEEE-754 construction (Phase 2 of #713) #717).
  3. Arithmetic operators: +, -, *, /, % (where applicable) and compound forms.
  4. Increment / decrement: ++, --.
  5. Comparison operators: ==, !=, <, <=, >, >=.
  6. Conversion-out: operator float(), operator double(), etc.
  7. Special-value handling: verify constexpr-clean.

Prerequisites

Per-type analysis required during audit. Common prerequisites for this Epic:

  • blockbinary arithmetic constexpr (already done for += -= ++ <<= |= in feat(blockbinary): promote arithmetic operators to constexpr (PR 2 of #713) #716; *= /= %= may still need promotion).
  • blocktriple / blocksignificand arithmetic constexpr where the type uses them.
  • extractFields (already BIT_CAST_CONSTEXPR) for IEEE-754 source extraction.
  • std::is_constant_evaluated() dispatch for non-constexpr platform intrinsics.

Acceptance

  • constexpr takum<...> a(2.0), b(3.0); constexpr auto c = a + b; (and analogous for *, -, /, +=, <) compiles and produces correct bit pattern.
  • static_assert smoke tests in the type's api.cpp (or constexpr.cpp) lock in the contract.
  • All existing regression suites for this type continue to pass on gcc + clang.
  • Cross-type regression sweep (since shared primitives affect every Universal type).

Related

Metadata

Metadata

Assignees

Projects

Status

No status

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions