C++ checked divisor special values
For admitted argument types, gcd_assign_r and lcm_assign_r shall interpret each source's specials according to that source's own policy. A source-policy NaN shall take precedence over infinity and shall request NaN assignment through the destination policy.
For non-NaN inputs, magnitudes shall use the nonnegative-integer divisibility order with one additional greatest element ∞, above zero as well as positive integers. The signs of infinities shall not affect these divisor operations. With either source infinite, the gcd shall be the other source's magnitude; two infinities shall give positive infinity. With either source infinite, the lcm shall be positive infinity, including when the other source is zero.
These mathematical values shall be independent of destination representability. Computing the selected absolute value or special-value assignment shall retain that operation's destination-policy range checks, rounding and result code. An unsupported NaN shall return a NaN-class result with V_UNREPRESENTABLE and no destination-value promise. An unsupported positive infinity shall retain the selected special-assignment outcome, including any directed finite bound. Finite-input gcd/lcm shall retain 🔗 2. Native integer greatest common divisor and least common multiple for native integers and 🔗 1. Exact unbounded integer greatest common divisor and least common multiple for unbounded integers; floating storage shall require finite integral operands and representable Euclidean intermediates.
All arguments shall have the same admitted raw storage type: a standard native integer, mpz_class, or a supported native floating-point type. Each argument may be raw or use an admitted Checked_Number policy. The destination may alias either source, and the sources may be the same object. Every source value shall mean its entry value; distinct sources shall retain their values. Live storage, supported numerical operations, sufficient resources and synchronization shall be required. Calls shall use an admitted rounding request and shall invoke no result handler. ROUND_NOT_NEEDED shall require an exact representable result and admitted intermediates. No coefficient-profile limit shall replace the selected scalar storage's own range and resource conditions.
Adding a greatest divisibility element preserves the ordinary finite meanings and defines the existing infinity/zero cases without applying extended-real multiplication to divisor operations. This lattice convention alone does not define Bezout coefficients for infinity.
Public header: <ppl.hh>; namespace Parma_Polyhedra_Library. The signatures denote the admitted raw/checked argument combinations:
template <typename To, typename X, typename Y> Result gcd_assign_r(To& to, const X& x, const Y& y, Rounding_Dir dir); template <typename To, typename X, typename Y> Result lcm_assign_r(To& to, const X& x, const Y& y, Rounding_Dir dir);
Cross finite negative, zero and positive operands with both infinity signs and NaN. Use independent finite gcd/lcm values and the explicit greatest- element convention. Check source/output aliases, source-policy classification, destination policies with and without specials, supported requests, unchanged distinct sources and output recovery after an unrepresentable outcome.
src/checked_ext_inlines.hh; src/Checked_Number_defs.hh; tests/checkedcontractedges1.cc, whose number-theory oracle records the added-greatest-element convention.
For supported native floating storage F and finite integral source entry values x, y, gcdext_assign_r shall assign a nonnegative gcd g and integral coefficients s, t satisfying xs + yt = g. Two zero sources shall give zero. No particular coefficient pair shall be required.
Sources, their absolute values, conversions, mathematical Euclidean integer quotients, remainders, and every evaluated coefficient product, difference and sign restoration shall be finite and exactly representable in the selected storage. A noninteger rounded division temporary may be used to derive the exact integer quotient. The requested result shall be V_EQ for admitted ordinary and strict requests, including ROUND_NOT_NEEDED.
All five arguments shall have the same raw type F, either raw or wrapped in admitted checked policies; the finite inputs shall be admitted by their source policies. The three outputs shall be live, independent and distinct from both sources. Sources may share an object and shall retain their values. The configured floating-rounding protocol and nontrapping arithmetic environment shall be in force, available resources shall suffice, and objects shall be synchronized. The hardware rounding direction shall be preserved. No rounding default or result handler shall be required or invoked.
Floating storage does not make real division into Euclidean integer division. For positive magnitudes with a representable integer quotient, downward division remains between that quotient and the next integer; truncation therefore recovers the exact Euclidean quotient.
Public header: <ppl.hh>; namespace Parma_Polyhedra_Library. The signature denotes supported same-raw-storage combinations:
template <typename G, typename S, typename T, typename X, typename Y> Result gcdext_assign_r(G& g, S& s, T& t, const X& x, const Y& y, Rounding_Dir dir);
Check independent exact gcds, integral coefficients and unbounded Bezout reconstruction over small signed and zero inputs. Include a positive ratio just below three that upward division can round to three, both source orders, sign combinations and valid result requests. Establish the exact representability of every required recurrence intermediate.
src/checked_inlines.hh; src/checked_float_inlines.hh; tests/floatingbezout1.cc.
For admitted same-raw-storage argument combinations, gcdext_assign_r shall recognize each source's NaN and infinities using that source's own policy before updating the coefficient outputs. With any such nonfinite operand, it shall request NaN assignment to g through the gcd output's policy and leave s and t unchanged. This shall include either infinity sign, two infinite operands and NaN/infinity combinations. No generalized Bezout identity shall be asserted for infinite operands.
A destination policy admitting NaN shall produce its NaN representation and return V_NAN. Otherwise the result shall be V_NAN | V_UNREPRESENTABLE with no value promise for g. Rejection shall apply to supported ordinary rounding requests and their strict-relation forms; ROUND_NOT_NEEDED shall require admitted finite input and an exact representable computation.
Finite inputs shall retain 🔗 1. Bounded native integer Bezout assignment for native integers and 🔗 2. Exact unbounded integer Bezout coefficients for unbounded integers. Supported floating storage shall require finite integral source values and exact representable conversions and Euclidean coefficient intermediates. A successful result shall have nonnegative g and coefficients satisfying xs + yt = g, without requiring a particular coefficient pair. The extended gcd/lcm convention in 🔗 1. Extended greatest common divisor and least common multiple shall not expand this finite Bezout domain.
The raw storage shall be a supported native integer, mpz_class or native floating-point type, shared by all five arguments. Arguments may be raw or use admitted checked policies. All three outputs shall be live, pairwise distinct and separate from both sources. Sources may be the same object and shall retain their entry values. Objects shall be synchronized and resources sufficient. The operation shall require no rounding default or result handler and shall invoke no handler; named assignment shall retain the single-handler protocol in 🔗 3. Checked integral divisor functions and Bezout outputs. Surviving outputs shall remain live and reassignable after rejection, without a rollback promise for g.
An extra greatest element in the divisibility order determines gcd/lcm but does not provide an integer linear identity involving infinity. Explicit rejection avoids presenting an arbitrary signed selector as a Bezout result or relying on multiplication of zero by infinity.
Public header: <ppl.hh>; namespace Parma_Polyhedra_Library. The signature denotes admitted raw/checked argument combinations:
template <typename G, typename S, typename T, typename X, typename Y> Result gcdext_assign_r(G& g, S& s, T& t, const X& x, const Y& y, Rounding_Dir dir);
Check independent finite gcd values and exact Bezout reconstruction across source signs, zeros, ordinary raw endpoints and supported numerical profiles. Cross infinities and NaN with each other and finite partners in both orders. Check unchanged coefficient sentinels and sources, destination policies with and without NaN, supported rejection requests, output recovery and exactly one named-operation handler decision after the output update.
src/checked_ext_inlines.hh; src/Checked_Number_defs.hh; src/Checked_Number_inlines.hh; tests/extendeddivisorcontract1.cc.