Parma Polyhedra Library requirements
C++ checked scalar arithmetic operators and result policies
1. Same-storage checked compound arithmetic PPL-SPEC-000903

Let N be Checked_Number<T, Policy>, where T is one of the eleven native integer types, mpz_class, mpq_class or a configured supported native floating format. The entry destination and right operand shall be finite admitted values, except for the infinite-divisor remainder case of 🔗 6. Remainder with a policy-admitted infinite divisor. For a raw T right operand or a Checked_Number<T, Other_Policy> right operand, the compound operators +=, -=, *=, /= and %= shall apply, respectively, add_assign_r, sub_assign_r, mul_assign_r, div_assign_r and rem_assign_r to the destination and the right operand's entry values.

The supplied direction shall be Policy::ROUND_DEFAULT_OPERATOR. The resulting numerical Result shall be delivered exactly once to Policy::handle_result, after the numerical operation. These same-storage forms shall require no constructor default and shall perform no numerical conversion of the right operand. A distinct checked source's policy handler and defaults shall not be consulted. If the destination handler returns, each operator shall return a reference to the destination.

Numerical values, result classes/relations, range outcomes and the corresponding domain, resource, alias and rounding prerequisites shall follow the underlying scalar operations:

In particular, division/remainder shall require a nonzero divisor; unchecked bounded use and exactness requests shall meet their stated representability conditions. The direction selected by the policy shall be admitted for the operation. Native floating directed/strict arithmetic shall satisfy its upward hardware-direction/backend-setup prerequisite. Shared rational remainder temporaries shall satisfy their synchronization condition. No coefficient-constant initialization shall be required by the wrapper.

The right operand may share destination storage, including through its raw reference, and each mathematical occurrence shall use its entry value. A distinct source shall remain unchanged. A handler exception shall propagate, leaving the destination live and reusable; its old payload need not be retained. Handler acceptance of an unsupported numerical outcome shall not promise a represented answer; an unspecified payload shall not be inspected before valid reuse. Object lifetime and access overlapping mutation shall follow 🔗 1. Finite checked scalar storage and copying. Hardware direction and exception-status effects shall follow the underlying numerical operation.

2. Same-policy checked binary arithmetic values PPL-SPEC-000904

For two finite N = Checked_Number<T, Policy> operands admitted by 🔗 1. Same-storage checked compound arithmetic, binary +, -, *, / and % shall produce a new N with the result of their corresponding numerical operation on the two entry values, in the written operand order. Both operands may be the same object and shall remain unchanged. The result shall own storage independent of both operands.

The arithmetic direction shall be Policy::ROUND_DEFAULT_OPERATOR and its numerical Result shall be delivered exactly once to Policy::handle_result. No constructor rounding default or conversion handler call shall be required merely to form or return the result. Elision or copying on return shall not change the numerical-handler count. If the handler throws, its exception shall propagate and no result object shall be delivered; the source operands shall remain unchanged.

Numerical outcome meanings, admissibility, hardware/resource prerequisites and accepted unsupported-result reuse shall follow 🔗 1. Same-storage checked compound arithmetic. Available resources shall suffice for the result object and underlying operation. The returned object shall be live, assignable and destructible.

PPL-SPEC-000905
3. Mixed operand conversion before checked arithmetic PPL-SPEC-000905

For a checked N = Checked_Number<T, Policy> operand, a raw native operand of scalar type S shall first be converted into an N using Policy::ROUND_DEFAULT_CONSTRUCTOR. The native families here shall be the PPL Is_Native scalar families in 🔗 1. Same-storage checked compound arithmetic, with configured availability for floating formats. Binary +, -, *, / and % shall then apply their numerical operation using Policy::ROUND_DEFAULT_OPERATOR, preserving the written operand order. The result type shall be N. This conversion shall occur even when S and T are the same type.

A compound operator on N with a raw or checked right operand of a different underlying scalar type S shall likewise first construct an N temporary from the right operand using the constructor default, then operate on the destination's entry value and that converted value using the operator default. The returned reference shall identify the destination. Same-storage direct compound forms shall retain 🔗 1. Same-storage checked compound arithmetic.

The constructor-conversion Result shall be delivered first to Policy::handle_result. If the handler returns, the arithmetic Result shall then be delivered once to that handler. Each completed stage shall contribute one call, in that order. The conversion and arithmetic may use different directions and classifications. Neither stage shall dispatch a checked source's own policy handler. The source and conversion prerequisites of 🔗 2. Finite checked scalar converting construction and assignment shall apply. If the conversion handler returns, its converted value shall be finite and meet the chosen arithmetic's operand preconditions; unsupported conversion payloads shall not be admitted as further numerical operands.

A conversion-handler exception shall stop before arithmetic. A compound destination shall then retain its entry value. An arithmetic-handler exception may follow destination mutation, with the live/reusable guarantee of 🔗 1. Same-storage checked compound arithmetic. Free binary operators shall preserve their original source operands in either case. Numerical answers shall describe the converted operand, rather than presume exact preservation of an inexactly converted source. Underlying result semantics, lifetime, resources, rounding/backend setup and synchronization prerequisites shall follow 🔗 1. Same-storage checked compound arithmetic.

4. Checked unary signs and prefix increment or decrement PPL-SPEC-000906

For finite N = Checked_Number<T, Policy> values admitted by 🔗 1. Same-storage checked compound arithmetic, unary + shall return an independent copy with the same value, including a native floating zero's sign. It shall consult no rounding default and invoke no policy handler.

Unary - shall return a new N whose value and numerical outcome follow neg_assign_r with Policy::ROUND_DEFAULT_OPERATOR. Its source shall remain unchanged. Native integer, unbounded integer, rational and native floating meanings shall follow 🔗 2. Native integer negation and absolute value, 🔗 1. Exact named arithmetic on unbounded integer storage, 🔗 4. Rational sign assignments and integral-valued rounding operations and 🔗 2. Exact finite native floating-point negation and absolute value, respectively.

Prefix ++ and -- shall apply add_assign_r or sub_assign_r to the destination's entry value and mathematical one, using the operator default. After handler acceptance they shall return a reference to the modified destination. Unary minus and each prefix operation shall deliver its numerical Result exactly once to Policy::handle_result and shall require no constructor default or extra conversion-handler call.

Domain/range, admitted directions, synchronization, resources and numerical backend/rounding prerequisites shall follow the corresponding operation and 🔗 1. Same-storage checked compound arithmetic. A handler exception shall propagate; prefix destinations shall remain live and reusable without a rollback promise. Unary result ownership and throwing-handler source preservation shall follow 🔗 2. Same-policy checked binary arithmetic values.

PPL-SPEC-001195
5. Checked postfix increment and decrement entry snapshots PPL-SPEC-001195

For a finite admitted entry value of N = Checked_Number<T, Policy>, postfix ++ and -- shall first obtain an independently owned same-type snapshot of that entry value. The snapshot shall preserve the finite value, including a native floating zero's sign, with the copying meaning of 🔗 1. Finite checked scalar storage and copying.

The numerical update shall apply add_assign_r or sub_assign_r, respectively, to the entry receiver and mathematical one, using Policy::ROUND_DEFAULT_OPERATOR. The operation shall deliver its numerical Result exactly once to Policy::handle_result. If the handler returns and construction of the returned value completes, the operator shall return the owned entry snapshot. Subsequent modification or destruction of either object shall not change or invalidate the other. Obtaining and returning the snapshot shall require no constructor rounding default and shall invoke no policy conversion handler.

The scalar families, policy capabilities, admitted directions, arithmetic and range meanings, resource and synchronization conditions, and numerical backend/FPU prerequisites shall follow 🔗 1. Same-storage checked compound arithmetic and the corresponding prefix update in 🔗 4. Checked unary signs and prefix increment or decrement. Canonical rational entry storage shall have a positive denominator. Handler acceptance of an unsupported numerical outcome shall not promise a represented receiver answer; an unspecified receiver payload shall not be inspected before valid reuse.

If construction of the entry snapshot fails, the receiver's entry value shall be preserved. An arithmetic or handler exception shall propagate, leaving the receiver live and reusable; its entry value need not be preserved. A failure while constructing the returned value after the numerical update shall not require receiver rollback. Hardware direction and exception-status effects shall follow the underlying arithmetic operation; the snapshot itself shall require no additional FPU setup or library initialization.

6. Remainder with a policy-admitted infinite divisor PPL-SPEC-001654

For a supported same-storage remainder backend, the dividend shall denote a finite value a under its own source policy and the divisor shall represent either signed infinity admitted by its own source policy. The value a shall be representable as finite under the destination policy. Storage shall be a supported native integer, mpz_class, mpq_class or configured native floating type; an infinity unavailable for the selected storage/policy shall not be supplied.

rem_assign_r(to, x, y, dir) shall store the exact entry value a and return V_EQ for either infinity sign and every admitted rounding request, including ROUND_NOT_NEEDED and ROUND_STRICT_RELATION. Each source shall be classified using its own policy. Distinct source objects not sharing destination storage shall remain unchanged. The output may alias either source through an admitted same-storage interface; the operation shall use the mathematical entry values under the source policies. The named call shall not invoke a result handler or require a rounding default.

The corresponding same-storage operator%= shall retain the operator rounding default, destination-reference result and single destination-handler dispatch of 🔗 1. Same-storage checked compound arithmetic. It shall require no source-policy handler or implicit source conversion. Finite-divisor behavior shall retain the selected scalar backend's contract.

Objects and special representations shall be live and admitted by their policies. Finite rational operands shall be canonical with positive denominator; an admitted PPL infinite representation shall follow 🔗 1. Typed special-marker assignment to native integer storage, 🔗 2. Typed special-marker assignment to GMP integer and rational storage or 🔗 4. Typed special-value assignment to native floating-point storage. The scalar backend's resource, synchronization, initialization and hardware prerequisites shall apply. Calls shall preserve hardware direction. No behavior for an infinite dividend or NaN operand shall be inferred from this contract.