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

C++ same-storage native integer named arithmetic

PPL-SPEC-000831
1. Exact same-storage native integer arithmetic
UID: PPL-SPEC-000831
STATUS: APPROVED
COMPONENT: NUMERICS
APPLICABILITY: IF_CPP
VERIFICATION_METHODS: Test, Analysis, Inspection
LANGUAGE: CPP
VISIBILITY: Public
RELATIONS (Parent):
STATEMENT:

For each of the eleven standard native integer storage types I, add_assign_r, sub_assign_r and mul_assign_r shall assign the exact mathematical sum, difference and product of their entry operands when the result is within the destination's finite range. They shall return V_EQ for each valid rounding direction, with or without ROUND_STRICT_RELATION. A rounding request shall not introduce a fractional approximation to an integer sum, difference or product.

Each argument shall have underlying storage type I, either as a raw integer or an admitted Checked_Number<I, Policy>. Entry operands shall be finite for their own source policies and lie in the destination policy's finite interval. That interval shall account for reserved representations as specified by 🔗 1. Bounded checked integer limits and reserved endpoints. A raw destination shall use the full native integer interval and overflow checking; a checked destination shall use its selected policy. If checking is disabled, the exact operation result shall be within that finite interval. Enabled range checking shall have the additional outcomes of 🔗 4. Checked native arithmetic range outcomes.

The output may alias either input, the two read-only inputs may alias each other, and all three arguments may be the same object. Every occurrence in the mathematical expression shall use its entry value. Distinct source objects shall remain unchanged. Named calls shall require no rounding default or result handler and shall not dispatch a handler. Objects shall be live and access overlapping mutation shall be synchronized. Calls shall require no library initialization, coefficient-constant stage or FPU setup and preserve hardware direction. Configured coefficient operators shall retain 🔗 3. Exact ordinary integral coefficient arithmetic; unbounded integer arithmetic shall retain 🔗 1. Exact named arithmetic on unbounded integer storage.

RATIONALE:

Exact integer arithmetic must retain its meaning across storage widths, signedness and policies without invoking a convenience-interface handler.

INTERFACE:

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

Result add_assign_r(To& to, const X& x, const Y& y, Rounding_Dir dir);
Result sub_assign_r(To& to, const X& x, const Y& y, Rounding_Dir dir);
Result mul_assign_r(To& to, const X& x, const Y& y, Rounding_Dir dir);
VERIFICATION_CRITERIA:

Use independent unbounded integer oracles across all eleven storage types, signed and unsigned endpoints, cancellation, zero, product sign combinations and representability boundaries. Check all valid exact requests, raw and checked operands, source preservation and every admitted alias. Exercise policies with and without overflow checking within their valid ranges.

SOURCE:

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

2. Directed native integer division and delegated truncation
UID: PPL-SPEC-000832
STATUS: APPROVED
COMPONENT: NUMERICS
APPLICABILITY: IF_CPP
VERIFICATION_METHODS: Test, Analysis, Inspection
LANGUAGE: CPP
VISIBILITY: Public
RELATIONS (Parent):
STATEMENT:

For argument types, entry-operand finite ranges and lifetime/alias prerequisites from 🔗 1. Exact same-storage native integer arithmetic, let the divisor b be nonzero and let q = a ⁄ b be the exact rational quotient. div_assign_r with ROUND_DOWN shall assign ⌊q⌋; with ROUND_UP it shall assign ⌈q⌉. A successful result shall give a relation containing the exact ordering of q relative to the stored integer. With ROUND_STRICT_RELATION, it shall identify precisely equality, strict greater-than or strict less-than through V_EQ, V_GT or V_LT.

ROUND_IGNORE shall store the quotient truncated toward zero and may return a relation containing equality and either strict order. A strict request shall identify the exact relation between q and that stored integer. ROUND_NOT_NEEDED shall require an exact representable quotient; it shall store that quotient and return a relation admitting equality. A strict exactness request shall return V_EQ. An out-of-range quotient shall follow 🔗 4. Checked native arithmetic range outcomes when checking is enabled, and shall be outside the unchecked successful-result precondition otherwise.

Quotient rounding and relation classification shall use entry operands even if the destination aliases the dividend or divisor. Sources not sharing the destination shall remain unchanged. Calls shall retain the handler, initialization, synchronization and hardware-direction conditions of 🔗 1. Exact same-storage native integer arithmetic.

RATIONALE:

Bounded integer division needs a defined rounding convention and an honest relation to the exact rational quotient, including delegated truncation.

INTERFACE:

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

Result div_assign_r(To& to, const X& x, const Y& y, Rounding_Dir dir);
VERIFICATION_CRITERIA:

Derive floor, ceiling and truncation from independent unbounded integer quotient/remainder calculations for every sign combination. Check exact and inexact quotients, zero dividends, full signed and unsigned endpoints, all admitted rounding and strictness requests, source aliases and preserved entry values. Assess checked range failure separately from successful representable division.

SOURCE:

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

3. Exact native truncated quotient and remainder
UID: PPL-SPEC-000833
STATUS: APPROVED
COMPONENT: NUMERICS
APPLICABILITY: IF_CPP
VERIFICATION_METHODS: Test, Analysis, Inspection
LANGUAGE: CPP
VISIBILITY: Public
RELATIONS (Parent):
STATEMENT:

For the same-storage finite operands and prerequisites of 🔗 1. Exact same-storage native integer arithmetic and a nonzero divisor b, idiv_assign_r shall assign the exact integer t = trunc(a ⁄ b) and rem_assign_r shall assign r = a − tb. For representable results, both shall return V_EQ for every valid rounding request, with or without ROUND_STRICT_RELATION. The named integer quotient shall not change to a floor or ceiling when the direction changes.

The identity a = tb + r shall hold mathematically. A nonzero remainder shall have the dividend's sign and satisfy |r| < |b|. Unsigned remainders shall be nonnegative. In particular, a signed minimum integer's remainder modulo -1 shall be exactly zero even when the corresponding positive quotient is outside storage range. The quotient's checked range outcome shall follow 🔗 4. Checked native arithmetic range outcomes; the remainder shall not require that quotient to be representable as an intermediate native integer.

Each operation shall permit every alias described by 🔗 1. Exact same-storage native integer arithmetic, using entry operands and preserving distinct sources. Its handler, initialization, synchronization and hardware-direction conditions shall follow that contract. ROUND_NOT_NEEDED shall require the selected operation's own integer result to be representable; it shall not require a ⁄ b itself to be integral when requesting the truncated quotient or remainder.

RATIONALE:

A truncated quotient and its remainder are exact integer operations. A quotient overflow must not prohibit a representable remainder or cause native undefined division during its computation.

INTERFACE:

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

Result idiv_assign_r(To& to, const X& x, const Y& y, Rounding_Dir dir);
Result rem_assign_r(To& to, const X& x, const Y& y, Rounding_Dir dir);
VERIFICATION_CRITERIA:

Check independent unbounded quotient/remainder and reconstruction oracles for all operand signs, exact and inexact division, zero dividends, every standard native storage type and endpoint values. Include signed minimum modulo minus one, all valid requests and every source/output alias. Check quotient overflow through its separate range contract.

SOURCE:

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

4. Checked native arithmetic range outcomes
UID: PPL-SPEC-000834
STATUS: APPROVED
COMPONENT: NUMERICS
APPLICABILITY: IF_CPP
VERIFICATION_METHODS: Test, Analysis, Inspection
LANGUAGE: CPP
VISIBILITY: Public
RELATIONS (Parent):
STATEMENT:

For native integer operations in 🔗 1. Exact same-storage native integer arithmetic, 🔗 2. Directed native integer division and delegated truncation and 🔗 3. Exact native truncated quotient and remainder, an overflow-checking destination shall detect an exact requested integer outside its finite interval rather than report a wrapped integer as successful exact arithmetic. For directed division the requested integer shall be its floor or ceiling; for delegated division it shall be its truncated quotient. Inputs shall satisfy the same-storage and finite entry-range conditions of those contracts. ROUND_NOT_NEEDED shall require exact representability and therefore exclude a range failure, with or without a strict flag.

For an exact integer below the finite lower endpoint, ROUND_UP shall store that endpoint and return V_LT_INF. ROUND_DOWN or ROUND_IGNORE shall return V_GT_MINUS_INFINITY, storing negative infinity if the destination policy admits it; otherwise the result shall add V_UNREPRESENTABLE. For an exact integer above the upper endpoint, ROUND_DOWN shall store that endpoint and return V_GT_SUP. ROUND_UP or ROUND_IGNORE shall return V_LT_PLUS_INFINITY, storing positive infinity if admitted; otherwise the result shall add V_UNREPRESENTABLE. A strict-relation flag shall not change these range outcomes. These codes shall describe the mathematical operation result relative to the endpoint or extended stored value.

When unrepresentability is reported, no numerical payload or rollback shall be promised, but the destination shall remain assignable and destructible. A range outcome shall not invoke a policy handler or automatically throw an overflow exception. Distinct source objects shall remain unchanged, and the aliasing, initialization, synchronization and hardware-direction conditions of 🔗 1. Exact same-storage native integer arithmetic shall continue to apply. A checked policy with overflow checking disabled shall not receive these detection guarantees.

RATIONALE:

An explicit Result interface must distinguish a finite inward endpoint, an admitted outward infinity and an unrepresentable outward bound without automatic exception policy dispatch.

INTERFACE:

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

Result add_assign_r(To& to, const X& x, const Y& y, Rounding_Dir dir);
Result sub_assign_r(To& to, const X& x, const Y& y, Rounding_Dir dir);
Result mul_assign_r(To& to, const X& x, const Y& y, Rounding_Dir dir);
Result div_assign_r(To& to, const X& x, const Y& y, Rounding_Dir dir);
Result idiv_assign_r(To& to, const X& x, const Y& y, Rounding_Dir dir);
VERIFICATION_CRITERIA:

Use independent unbounded arithmetic to generate results immediately beyond both finite endpoints and larger range failures. Check literal result codes, inward endpoint storage, admitted outward infinity and unrepresentability for all native storage types, policy reservation combinations, directed and delegated requests, aliases and reusable outputs. Verify that a rejecting policy handler is never called and distinct inputs remain unchanged.

SOURCE:

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