C++ finite native floating-point binary arithmetic
For admitted source/destination types and rounding requests in 🔗 4. Rounding, result classes and state for finite native binary arithmetic, add_assign_r(to, x, y, dir) shall compute the exact-real expression a + b and sub_assign_r the expression a − b, where a and b are the finite represented entry values of the two sources. The destination shall hold the rounded value and the returned Result shall describe it as specified there. Overflow into an infinite bound shall not introduce a bounded coefficient intermediate.
For an exact zero sum, equal-sign zero operands shall retain their common sign. All other exact-zero sums, including cancellation of nonzero values, shall produce negative zero under downward evaluation and positive zero under upward, toward-zero or nearest-even evaluation. For subtraction this rule shall apply to the signs of x and the negation of y. A nonzero exact result rounded to zero shall retain that real result's sign.
Source aliases, object validity, preservation, synchronization, backend setup, initialization independence and floating-point state prerequisites shall follow 🔗 4. Rounding, result classes and state for finite native binary arithmetic.
Addition and subtraction supply native directed bounds while preserving cancellation and IEEE signed-zero distinctions needed by subsequent numerical operations.
Public header: <ppl.hh>; effective template instantiations for the admitted same-format To, Left and Right types:
Result add_assign_r(To& to, const Left& x, const Right& y, Rounding_Dir dir); Result sub_assign_r(To& to, const Left& x, const Right& y, Rounding_Dir dir);
Compare exact dyadic sums and differences with independent rational oracles for all admitted raw/checked operand forms. Include cancellation, signed zeros, adjacent values, precision loss, subnormal boundaries and range-limit results. Check tight bounds, statuses, zero signs, aliases, distinct-source preservation and hardware direction.
src/checked_float_inlines.hh; src/Checked_Number_defs.hh and src/Checked_Number_inlines.hh; tests/floatingarithmeticspec1.cc; tests/numericpublic1.cc.
For admitted source/destination types and rounding requests in 🔗 4. Rounding, result classes and state for finite native binary arithmetic, mul_assign_r(to, x, y, dir) shall compute the exact-real product ab of the finite represented source entry values. It shall assign the rounded product and return the Result specified there. A zero product, including one produced by underflow, shall have the exclusive-or of the source sign bits. This shall include both signs of zero, ordinary values, finite extrema and subnormals.
No bounded coefficient intermediate shall limit the native format's range. Source aliases, object validity, preservation, synchronization, backend setup, initialization independence and floating-point state prerequisites shall follow 🔗 4. Rounding, result classes and state for finite native binary arithmetic.
A native product must bound its exact represented operands through both precision loss and underflow. Its zero sign remains defined even when the exact nonzero product is too small for finite nonzero storage.
Public header: <ppl.hh>; effective template instantiations for the admitted same-format To, Left and Right types:
Result mul_assign_r(To& to, const Left& x, const Right& y, Rounding_Dir dir);
Use independent exact rational products across signs, signed zeros, significand boundaries, powers of two, subnormal/half-subnormal cases and finite range limits. Cross all admitted operand forms, check tight directed/delegated values, statuses, zero signs, aliases and state preservation.
src/checked_float_inlines.hh; src/Checked_Number_defs.hh and src/Checked_Number_inlines.hh; tests/floatingarithmeticspec1.cc; tests/numericpublic1.cc.
For admitted source/destination types and rounding requests in 🔗 4. Rounding, result classes and state for finite native binary arithmetic, div_assign_r(to, x, y, dir) shall require a nonzero finite divisor and a finite numerator. It shall compute the exact-real quotient a ⁄ b from their represented entry values, assign its rounded value and return the Result specified there. A zero quotient, including one produced by underflow, shall have the exclusive-or of the source sign bits.
The quotient may be nondyadic and shall not be described as exact merely because the division completed. No bounded coefficient intermediate shall limit the native format's range. Source aliases, object validity, preservation, synchronization, backend setup, initialization independence and floating-point state prerequisites shall follow 🔗 4. Rounding, result classes and state for finite native binary arithmetic.
Finite division needs a nonzero-divisor precondition and a distinction between exact dyadic quotients and conservative bounds on nondyadic real quotients.
Public header: <ppl.hh>; effective template instantiations for the admitted same-format To, Left and Right types:
Result div_assign_r(To& to, const Left& x, const Right& y, Rounding_Dir dir);
Compare quotients with exact rational oracles for signed ratios such as one- third, exact powers of two, signed-zero numerators, precision boundaries, subnormals, tiny nonzero divisors and finite range limits. Cross all admitted raw/checked forms and aliases, checking tight bounds, precision statuses, zero signs, source preservation and hardware direction.
src/checked_float_inlines.hh; src/Checked_Number_defs.hh and src/Checked_Number_inlines.hh; tests/floatingarithmeticspec1.cc; tests/numericpublic1.cc.
The native storage format F shall be configured and supported as in 🔗 1. Supported exact integer and rational conversion to native floating storage. Each destination and source shall be F or Checked_Number<F, Check_Overflow_Policy<F>>, with the same format for all operands. Sources shall be finite and shall meet the particular operation's mathematical preconditions in 🔗 1. Finite native floating-point addition and subtraction, 🔗 2. Finite native floating-point multiplication or 🔗 3. Finite native floating-point division by a nonzero value. Let q be that operation's exact-real result.
ROUND_DOWN shall assign the greatest native representable bound no greater than q, and ROUND_UP the least bound no less than it, including subnormal and infinite bounds. Without a strict flag it shall return the downward weak relation V_GE or upward V_LE. With ROUND_STRICT_RELATION and definite native inexact information, an exact result shall have relation VR_EQ, an inexact downward result VR_GT and an inexact upward result VR_LT. If native inexact information is unavailable, the corresponding weak relation shall be returned.
ROUND_IGNORE shall evaluate using the current hardware direction, including nearest-even midpoint selection. An unflagged request shall have lazy relation VR_LGE. A strict delegated request with definite inexact information shall have VR_EQ for exactness and VR_NE for inexactness; unavailable information shall give VR_LGE. ROUND_NOT_NEEDED shall require q to be exactly representable as a finite value. It shall assign that exact value, return V_EQ in an assertion-enabled build and may return lazy V_LGE in a build defining NDEBUG. A strict no-rounding-needed request shall retain that precondition and return V_EQ.
The returned class shall be VC_NORMAL for a finite computed value, VC_PLUS_INFINITY for positive infinity and VC_MINUS_INFINITY for negative infinity, combined with the corresponding relation. These native values shall be representable without V_UNREPRESENTABLE. For an exact real magnitude exceeding the finite maximum, inward directed evaluation shall return the signed finite endpoint and outward evaluation the corresponding infinity. Delegated range behavior shall follow the native hardware mode and nearest-overflow threshold in 🔗 6. Range limits in conversion of finite native scalars to floating point. A finite inward endpoint shall not promise an integer-overflow annotation.
Directed, strict and no-rounding-needed requests shall require upward hardware rounding. An unflagged delegated request shall require no particular current direction. Calls shall preserve that direction; accrued exception flags shall be unspecified and floating-point exceptions shall be nontrapping. Native FPU backend setup shall follow 🔗 1. Directed native integral conversion to native floating-point storage. No library/thread initialization object shall be required on backends requiring no setup, and no coefficient-constant stage or shared numerical temporary pool shall be required.
The destination shall be live and assignable. It may be either source; the sources may designate the same object; and storage may be shared through a checked object's raw-value reference. Results shall use both source entry values. Sources with storage distinct from the destination shall remain unchanged. Callers shall synchronize access against concurrent mutation. The _r interfaces shall return their results without policy-handler dispatch.
Native binary arithmetic needs one consistent meaning for rounded payloads, relation precision, result classes and the FPU environment. A correct mathematical bound does not excuse an incorrect annotation of an infinite computed value.
Public header: <ppl.hh>; effective template instantiations for the admitted same-format To, Left and Right types:
Result add_assign_r(To& to, const Left& x, const Right& y, Rounding_Dir dir); Result sub_assign_r(To& to, const Left& x, const Right& y, Rounding_Dir dir); Result mul_assign_r(To& to, const Left& x, const Right& y, Rounding_Dir dir); Result div_assign_r(To& to, const Left& x, const Right& y, Rounding_Dir dir);
Cross the binary operations and admitted raw/checked source/destination forms with exact rational value oracles. Check adjacent directed bounds, all hardware modes for unflagged delegation, nearest-even ties, weak/strict/unknown classifications, valid exactness requests, finite and infinite range results, signed zeros and source/destination aliases. Verify unchanged direction, no initialization-stage dependence on setup-free backends and compilation without unavailable native formats.
src/checked_float_inlines.hh; src/Checked_Number_defs.hh and src/Checked_Number_inlines.hh; tests/floatingarithmeticspec1.cc; tests/numericpublic1.cc.