Parma Polyhedra Library requirements
C++ same-storage native integer dyadic arithmetic

C++ same-storage native integer dyadic arithmetic

PPL-SPEC-000837
1. Native integer arithmetic with exact powers of two
UID: PPL-SPEC-000837
STATUS: APPROVED
COMPONENT: NUMERICS
APPLICABILITY: IF_CPP
VERIFICATION_METHODS: Test, Analysis, Inspection
LANGUAGE: CPP
VISIBILITY: Public
RELATIONS (Parent):
STATEMENT:

For the eleven standard native integer storage types and same-storage raw/checked forms in 🔗 1. Exact same-storage native integer arithmetic, let m = 2e for an unsigned int exponent e. add_2exp_assign_r, sub_2exp_assign_r and mul_2exp_assign_r shall assign the exact mathematical integers x + m, x − m and xm when those results lie in the destination policy's finite interval. Each shall return V_EQ for every valid rounding request, including a strict flag.

With overflow checking enabled, all unsigned exponent values shall be admitted. A checked result outside the finite interval shall have the endpoint, extended-value or unrepresentability outcome of 🔗 4. Checked native arithmetic range outcomes. In particular, zero multiplied by any such power shall remain exact zero, without requiring the power to fit native storage. ROUND_NOT_NEEDED shall require a representable result.

For unchecked add/subtract, both the power and the exact result shall be representable in native I and the result shall be finite for the selected policy. For unchecked multiplication, the exponent shall be less than the native storage width in bits and the exact result shall be finite and representable. These preconditions shall apply even to a zero source when an unchecked implementation forms a native shift.

The source and destination may be the same object. Calculations shall use entry source values and preserve distinct sources. No rounding default or handler shall be required or invoked. Object lifetime, synchronization, initialization and hardware-direction conditions shall follow 🔗 1. Exact same-storage native integer arithmetic. The mathematical definition shall not impose an intermediate native limit on a checked operation's power of two.

RATIONALE:

An exponent is a mathematical power parameter. Checked operations can decide large-power range outcomes without performing an invalid native shift; unchecked calls require explicit intermediate and shift preconditions.

INTERFACE:

Public header: <ppl.hh>; effective instantiations in Parma_Polyhedra_Library for admitted argument types:

Result add_2exp_assign_r(To& to, const From& source, unsigned int e,
                         Rounding_Dir dir);
Result sub_2exp_assign_r(To& to, const From& source, unsigned int e,
                         Rounding_Dir dir);
Result mul_2exp_assign_r(To& to, const From& source, unsigned int e,
                         Rounding_Dir dir);
VERIFICATION_CRITERIA:

Use independent unbounded or symbolic integer oracles for every native width, zero, signed minima, finite endpoints, cancellation, and exponents zero, below/at/above the sign and storage boundaries and UINT_MAX. Check valid exact requests, all range outcomes, raw/checked forms, source aliases and preserved hardware direction. Keep unchecked calls within both shift and intermediate representability preconditions.

SOURCE:

src/checked_int_inlines.hh; src/checked_ext_inlines.hh; src/Checked_Number_defs.hh; src/Checked_Number_inlines.hh; tests/nativeintegerdyadicspec1.cc.

PPL-SPEC-000838
2. Directed native integer division by powers of two
UID: PPL-SPEC-000838
STATUS: APPROVED
COMPONENT: NUMERICS
APPLICABILITY: IF_CPP
VERIFICATION_METHODS: Test, Analysis, Inspection
LANGUAGE: CPP
VISIBILITY: Public
RELATIONS (Parent):
STATEMENT:

For the same-storage finite entry values and prerequisites in 🔗 1. Exact same-storage native integer arithmetic, div_2exp_assign_r shall divide the exact integer source by 2e, for every unsigned int exponent e. ROUND_DOWN shall store its floor, ROUND_UP its ceiling and ROUND_IGNORE its truncation toward zero. Every stored result shall be finite and representable. No exponent shall cause an invalid native shift, including one equal to or greater than the storage width.

A successful result shall report a relation containing the exact rational quotient's ordering relative to the stored integer. With ROUND_STRICT_RELATION it shall return precisely V_EQ, V_GT or V_LT for equality, an exact quotient greater than the stored result, or one smaller than it. ROUND_NOT_NEEDED shall require exact divisibility by 2e; it shall store the exact quotient and return a relation admitting equality. Its strict form shall return V_EQ.

An exponent of zero shall preserve the integer value. For exponents greater than the storage width, a nonzero positive source shall have floor zero and ceiling one; a negative source shall have floor minus one and ceiling zero. Delegated truncation shall give zero in both cases. Zero shall remain zero for every exponent. Source aliases, preservation, handler independence, initialization, synchronization and hardware-direction conditions shall follow 🔗 1. Exact same-storage native integer arithmetic.

RATIONALE:

Integer division by a power of two must retain its directed mathematical meaning beyond the native shift width, including negative fractions and exactness classification.

INTERFACE:

Public header: <ppl.hh>; effective instantiations in Parma_Polyhedra_Library for admitted argument types:

Result div_2exp_assign_r(To& to, const From& source, unsigned int e,
                         Rounding_Dir dir);
VERIFICATION_CRITERIA:

Derive exact quotient/remainder, directed integer and relation oracles using unbounded arithmetic or symbolic signs for very large exponents. Exercise all eleven storage types, every valid request, signed zero-crossing cases, finite endpoints, exact divisibility and exponents through UINT_MAX. Check same-object assignment, raw/checked forms, unchanged sources and hardware direction without library initialization.

SOURCE:

src/checked_int_inlines.hh; src/checked_ext_inlines.hh; src/Checked_Number_defs.hh; src/Checked_Number_inlines.hh; tests/nativeintegerdyadicspec1.cc.

PPL-SPEC-000839
3. Centered and nonnegative native integer dyadic residues
UID: PPL-SPEC-000839
STATUS: APPROVED
COMPONENT: NUMERICS
APPLICABILITY: IF_CPP
VERIFICATION_METHODS: Test, Analysis, Inspection
LANGUAGE: CPP
VISIBILITY: Public
RELATIONS (Parent):
STATEMENT:

For the same-storage finite entry operands and prerequisites in 🔗 1. Exact same-storage native integer arithmetic, let m = 2e, where e is any unsigned int exponent. umod_2exp_assign_r shall assign the unique integer u with 0 ≤ u < m and x − u divisible by m. smod_2exp_assign_r shall assign s = u when 2u < m, and s = u − m otherwise. The centered interval shall therefore be [ − m ⁄ 2, m ⁄ 2); an exact half-modulus tie shall select its negative representative. Exponent zero shall give zero for both operations.

A representable finite residue shall return V_EQ for every valid rounding request, including strict requests. The rounding direction shall not choose a different residue convention. When checking is enabled, a residue outside the policy's finite interval shall instead have the range outcome of 🔗 4. Checked native arithmetic range outcomes, using that residue as the exact requested integer. Reserved infinity/NaN representations shall not be reported as successful finite residues. This shall include negative centered residues in unsigned storage and nonnegative signed-storage residues crossing a policy-reserved upper endpoint.

Unchecked calls shall require the selected residue to be finite and representable. ROUND_NOT_NEEDED shall require representability, with or without a strict flag. No exponent shall cause an invalid native shift. The source and destination may alias, and a distinct source shall remain unchanged. Handler independence, output reusability after an unrepresentable range outcome, initialization, lifetime, synchronization and preserved hardware direction shall follow 🔗 1. Exact same-storage native integer arithmetic and 🔗 4. Checked native arithmetic range outcomes.

RATIONALE:

A residue convention includes its sign and half-modulus tie rule. Its exact mathematical value must also respect the selected policy finite interval, which may be smaller than the underlying native storage range.

INTERFACE:

Public header: <ppl.hh>; effective instantiations in Parma_Polyhedra_Library for admitted argument types:

Result smod_2exp_assign_r(To& to, const From& source, unsigned int e,
                          Rounding_Dir dir);
Result umod_2exp_assign_r(To& to, const From& source, unsigned int e,
                          Rounding_Dir dir);
VERIFICATION_CRITERIA:

Use independent nonnegative modulo and centered tie oracles for all native types, zero, both signs, finite endpoints, half-modulus boundaries, exponent zero and storage-width boundaries through UINT_MAX. Check exact payloads or literal policy-aware range outcomes, source aliases, raw/checked forms and all valid requests. Include unsigned negative centered results and signed nonnegative residues at policy-reserved positive endpoints.

SOURCE:

src/checked_int_inlines.hh; src/checked_ext_inlines.hh; src/Checked_Number_defs.hh; src/Checked_Number_inlines.hh; tests/nativeintegerdyadicspec1.cc.