Parma Polyhedra Library requirements
C++ finite rational numerical operations
1. Exact rational assignment from rational and integral sources PPL-SPEC-000091

assign_r(to, from, dir) shall replace to by the exact value of a canonical rational source, mpz_class source or supported native integral source, and shall return V_EQ. Integral assignment shall produce canonical denominator one, including for zero, both signs and signed and unsigned native endpoints. Rational self-assignment shall preserve its value.

The native source types shall be char, signed char, unsigned char, short, unsigned short, int, unsigned int, long, unsigned long, long long and unsigned long long. Their full representable ranges shall be admitted. The directions ROUND_DOWN, ROUND_UP, ROUND_IGNORE and ROUND_NOT_NEEDED, with an optional ROUND_STRICT_RELATION flag, shall not change this exact value or result classification.

Rational sources shall be finite canonical mpq_class objects: the denominator shall be positive, and numerator and denominator shall be coprime; zero shall be represented as 0/1. The destination shall be a live rational object. Distinct sources shall remain unchanged. Callers shall synchronize access overlapping modification of an argument object. No library initialization object, thread initialization or coefficient-constant stage shall be required. Available resources shall limit computation; no fixed coefficient-width bound shall be imposed on rational arithmetic itself.

PPL-SPEC-000092
2. Exact rational assignment of finite native floating-point values PPL-SPEC-000092

For a finite source of type float, double or long double whose corresponding PPL_SUPPORTED_FLOAT, PPL_SUPPORTED_DOUBLE or PPL_SUPPORTED_LONG_DOUBLE macro is nonzero, assign_r(to, from, dir) shall assign its exact mathematical value as a canonical rational and return V_EQ. This shall include signed zero, subnormal values where supported, and the finite endpoints of the source format. Either sign of floating-point zero shall produce rational 0/1. The result shall preserve the represented binary floating-point value, without substituting a nearby decimal interpretation.

ROUND_DOWN, ROUND_UP, ROUND_IGNORE and ROUND_NOT_NEEDED, with an optional ROUND_STRICT_RELATION flag, shall not change the assigned value or status. The current floating-point rounding direction shall not change the exact rational value. Nonfinite inputs and numeric policies for encoded special rationals shall be outside this finite-value contract.

The destination shall be a live rational object. Synchronization and resource prerequisites shall follow 🔗 1. Exact rational assignment from rational and integral sources. The floating-point source shall remain unchanged.

3. Exact finite rational addition, subtraction, multiplication and division PPL-SPEC-000093

For source entry values a and b, add_assign_r, sub_assign_r and mul_assign_r shall assign a + b, a − b and ab, respectively. div_assign_r shall require b ≠ 0 and assign a ⁄ b. Each successful operation shall produce a canonical rational and return V_EQ. This shall include cancellation, zero numerators and arbitrarily large finite integral numerator or denominator values within available resources.

The two sources may be the same object. The directions ROUND_DOWN, ROUND_UP, ROUND_IGNORE and ROUND_NOT_NEEDED, with an optional ROUND_STRICT_RELATION flag, shall not change the exact value or status. A transparent rational policy shall not promise rejection of a zero divisor.

Canonical operands, synchronization and resource prerequisites shall follow 🔗 1. Exact rational assignment from rational and integral sources. The destination shall be a live rational object and may be any source; the operation shall use every operand's entry value. Distinct sources shall remain unchanged.

4. Rational sign assignments and integral-valued rounding operations PPL-SPEC-000094

For source entry value a, neg_assign_r and abs_assign_r shall assign  − a and |a|. floor_assign_r, ceil_assign_r and trunc_assign_r shall assign, respectively, ⌊a⌋, ⌈a⌉ and trunc(a), where truncation is toward zero. The three integral-valued results shall have denominator one.

Each successful call shall return V_EQ for its specified operation's result, including rounding a nonintegral source to an integer. The status shall not assert that this rounded integer equals the original source. ROUND_DOWN, ROUND_UP, ROUND_IGNORE and ROUND_NOT_NEEDED, with an optional ROUND_STRICT_RELATION flag, shall leave the specified operation result and status unchanged.

Canonical operands, synchronization and resource prerequisites shall follow 🔗 1. Exact rational assignment from rational and integral sources. The destination shall be a live rational object and may be any source; the operation shall use every operand's entry value. Distinct sources shall remain unchanged.

5. Truncated rational quotient and signed rational remainder PPL-SPEC-000095

For rational source entry values a and nonzero b, idiv_assign_r(to, x, y, dir) shall assign q = trunc(a ⁄ b) as a canonical rational with denominator one. rem_assign_r(to, x, y, dir) shall assign r = a − btrunc(a ⁄ b). The remainder shall satisfy |r| < |b|; a nonzero remainder shall have the sign of a. Each successful call shall return V_EQ for its specified operation.

The two sources may be the same object. The directions ROUND_DOWN, ROUND_UP, ROUND_IGNORE and ROUND_NOT_NEEDED, with an optional ROUND_STRICT_RELATION flag, shall not change these truncation and remainder conventions or the returned exact status. A zero-divisor rejection guarantee shall not be inferred from this contract.

Canonical operands, synchronization and resource prerequisites shall follow 🔗 1. Exact rational assignment from rational and integral sources. The destination shall be a live rational object and may be any source; the operation shall use every operand's entry value. Distinct sources shall remain unchanged.

With a non-thread-safe build, calls to rem_assign_r shall not overlap PPL arithmetic in another thread. A thread-safe build shall provide independent temporary storage for each thread.

6. Exact rational operations with powers of two PPL-SPEC-000096

For source entry value a and unsigned int exponent e, let m = 2e. add_2exp_assign_r and sub_2exp_assign_r shall assign a + m and a − m. mul_2exp_assign_r and div_2exp_assign_r shall assign am and a ⁄ m.

umod_2exp_assign_r shall assign ru = a − m⌊a ⁄ m⌋, satisfying 0 ≤ ru < m. smod_2exp_assign_r shall assign rs = a − m⌊a ⁄ m + 1 ⁄ 2⌋, satisfying  − m ⁄ 2 ≤ rs < m ⁄ 2; the half-period tie shall select the negative endpoint. These remainder operations shall preserve fractional parts as required by their mathematical definitions.

Every successful call shall produce a canonical rational and return V_EQ. Exponent zero shall mean m = 1. The exponent range shall be subject to available resources; it shall not be capped by the configured coefficient width. ROUND_DOWN, ROUND_UP, ROUND_IGNORE and ROUND_NOT_NEEDED, with an optional ROUND_STRICT_RELATION flag, shall not change these exact results.

Canonical operands, synchronization and resource prerequisites shall follow 🔗 1. Exact rational assignment from rational and integral sources. The destination shall be a live rational object and may be any source; the operation shall use every operand's entry value. Distinct sources shall remain unchanged.

With a non-thread-safe build, calls to add_2exp_assign_r or sub_2exp_assign_r shall not overlap PPL arithmetic in another thread. A thread-safe build shall provide independent temporary storage for each thread.

PPL-SPEC-000097
7. Exact rational product accumulation and subtraction PPL-SPEC-000097

For destination and source entry values d, a and b, add_mul_assign_r shall assign d + ab and sub_mul_assign_r shall assign d − ab. Each successful call shall produce a canonical rational and return V_EQ. The destination may be either or both sources; the two sources may be the same object.

ROUND_DOWN, ROUND_UP, ROUND_IGNORE and ROUND_NOT_NEEDED, with an optional ROUND_STRICT_RELATION flag, shall not change the exact value or status. There shall be no bounded coefficient intermediate-range restriction on these rational operations.

Canonical operands, synchronization and resource prerequisites shall follow 🔗 1. Exact rational assignment from rational and integral sources. The destination shall be a live rational object and may be any source; the operation shall use every operand's entry value. Distinct sources shall remain unchanged.

PPL-SPEC-000098
8. Rational canonical-form inspection and coefficient component extraction PPL-SPEC-000098

is_canonical(x) shall return true exactly when x has positive denominator and coprime numerator and denominator. It shall admit a live mpq_class object with unreduced components or nonpositive denominator for inspection, preserve those components and return false when they violate the canonical conditions. It shall not normalize the inspected source.

For a finite canonical rational source with mathematical value n ⁄ d, numer_denom(from, numer, denom) shall assign its canonical numerator n and positive denominator d to the two configured coefficient outputs. The outputs shall be distinct and distinct from the source. Successful bounded-profile extraction shall require both components to be representable in the configured coefficient range. Native callers shall satisfy that range condition. Checked component overflow shall report std::overflow_error and retain the surviving-output guarantee of 🔗 5. Checked coefficient overflow and result-policy dispatch; an earlier output assignment need not be rolled back.

No library initialization object, thread initialization or coefficient- constant stage shall be required. Callers shall synchronize overlapping modifications of argument objects and serialize these temporary-storage operations across threads in a non-thread-safe build. A thread-safe build shall provide independent temporary storage for each thread. Available resources shall limit temporary rational storage.

PPL-SPEC-000099
9. Finite rational sign, comparison and numeric classification PPL-SPEC-000099

For finite canonical rational values, sgn(x) shall return -1, 0 or 1 according to the sign of the numerator. cmp(x, y) shall return an int whose sign agrees with the mathematical ordering of the rationals; a nonzero magnitude shall not be prescribed.

is_integer(x) shall return true exactly when the canonical denominator is one. is_not_a_number(x), is_minus_infinity(x) and is_plus_infinity(x) shall each return false. These predicates shall return bool and shall preserve the operands. They shall not give a finite rational value an infinity merely because an associated bounded coefficient profile cannot hold its numerator or denominator. The admitted GMP special representations and their extended-integrality classification shall follow 🔗 2. GMP integer and rational special-value classification.

Canonical inputs, synchronization and resource prerequisites shall follow 🔗 1. Exact rational assignment from rational and integral sources.