Parma Polyhedra Library requirements
C++ finite native floating quotient and residues

C++ finite native floating quotient and residues

UID:
VERSION:
CLASSIFICATION:
PREFIX:
Type
Level
MID
UID
REFS
Title
Statement
Rationale
Comment
BIBLIOGRAPHY
STATUS
COMPONENT
APPLICABILITY
VERIFICATION_METHODS
VERIFICATION_CRITERIA
SOURCE
LANGUAGE
VISIBILITY
INTERFACE
SW_SPEC
1
PPL-SPEC-000506
Truncated native floating quotient before storage rounding

The source and destination types shall be the admitted same-format native or Checked_Number<F, Check_Overflow_Policy<F>> types in 🔗 4. Rounding, result classes and state for finite native binary arithmetic. Both sources shall be finite, with represented values a and b, and b ≠ 0. Let n = trunc(a ⁄ b), where truncation is toward zero in exact real arithmetic. idiv_assign_r shall round and store n in F; it shall not substitute truncation of an already rounded real quotient.

ROUND_DOWN shall select the greatest representable value not exceeding n; ROUND_UP shall select the least representable value not less than n, with admitted infinite endpoints as in 🔗 5. Floating conversion overflow thresholds and computed-value classes. For n in the finite native range, ROUND_IGNORE shall round n toward zero, independently of the caller's hardware direction. Outside that range, it shall follow the explicit delegated overflow value-selection rules in 🔗 5. Floating conversion overflow thresholds and computed-value classes, including their signed infinite endpoints. ROUND_NOT_NEEDED shall require n to be finite and exactly representable in F. Adding ROUND_STRICT_RELATION shall retain the same value-selection rules. For a finite result, the returned relation shall be V_EQ, V_GT or V_LT according as n is equal to, greater than or less than the stored value. Infinite endpoints shall carry their actual result class and relation: positive infinity shall return V_LT_PLUS_INFINITY and negative infinity shall return V_GT_MINUS_INFINITY, also for nonstrict requests. A zero result shall have the exclusive-or of the source signs.

The native hardware direction shall be upward, except that an exactly representable integral real quotient a ⁄ b shall require no particular hardware direction. The operation shall preserve the hardware direction. Native backend setup, live-object and source/destination alias rules, exception conditions and initialization independence shall follow 🔗 4. Rounding, result classes and state for finite native binary arithmetic. The operands may alias each other. Distinct source objects shall remain unchanged. Resources for exact integer/rational temporaries shall be available, and their temporary pools shall be serialized in a build without thread-safe support. Neither the configured coefficient range nor irrational-precision settings shall restrict the quotient.

Truncating an approximate real quotient can cross an integer boundary. The integer quotient must be established before any unavoidable destination precision loss, including when the mathematical quotient exceeds the native format's consecutive-integer range.

APPROVED
NUMERICS
IF_CPP, NATIVE_FP_AVAILABLE
Test, Analysis, Inspection

Use exact dyadic source extraction and an independent integer quotient oracle. Check all source signs, signed zero, rounded quotients adjacent to integer boundaries, consecutive-integer precision limits, exact large quotients and inexact large integer storage. Exercise direct, strict, delegated and admitted exactness requests, finite/infinite range endpoints, raw/checked combinations, operand and destination aliases, source preservation and hardware direction.

src/checked_float_inlines.hh; src/Checked_Number_defs.hh and src/Checked_Number_inlines.hh; tests/floatingresiduesspec1.cc.

CPP
Public

Public header: <ppl.hh>; effective template instantiations for admitted same-format To, Left and Right types:

Result idiv_assign_r(To& to, const Left& left, const Right& right,
                     Rounding_Dir dir);
SW_SPEC
2
PPL-SPEC-000507
Exact truncating remainder of finite native floating values

For the finite same-format source/destination types and nonzero divisor in 🔗 1. Truncated native floating quotient before storage rounding, rem_assign_r shall assign exactly r = a − trunc(a ⁄ b)b. It shall satisfy |r| < |b|; a nonzero remainder shall have the sign of a and a zero remainder shall retain the first source's sign. The reconstruction identity shall use the mathematical truncated quotient, even when that integer is not exactly representable in F.

All four valid rounding directions, with or without ROUND_STRICT_RELATION, shall return V_EQ and the same exact value. No particular hardware direction or inexact-flag support shall be required; the hardware direction shall remain unchanged. Native backend availability, object validity, source/destination and source/source aliases, source preservation, initialization independence and exception conditions shall follow 🔗 1. Truncated native floating quotient before storage rounding, without its upward-direction or exact-temporary resource prerequisites. No irrational-precision setting or coefficient range shall affect the remainder.

Finite binary floating values admit an exact truncating remainder even when their integer quotient is too large to store exactly in the same format. Explicit signs and reconstruction semantics distinguish this operation from nearest-integer remainder conventions.

APPROVED
NUMERICS
IF_CPP, NATIVE_FP_AVAILABLE
Test, Analysis, Inspection

Compare with exact dyadic dividend reconstruction for every source sign combination, exact and inexact division, signed zero, subnormal operands and extreme quotient magnitudes. Exercise all eight requests under every available hardware direction, raw/checked forms, all admitted aliases and exact result classification without relying on the native quotient operation as the oracle.

src/checked_float_inlines.hh; src/Checked_Number_defs.hh and src/Checked_Number_inlines.hh; tests/floatingresiduesspec1.cc.

CPP
Public

Public header: <ppl.hh>; effective template instantiations for admitted same-format To, Left and Right types:

Result rem_assign_r(To& to, const Left& left, const Right& right,
                    Rounding_Dir dir);
SW_SPEC
3
PPL-SPEC-000508
Exact centered native residue modulo a power of two

The source/destination types shall be as in 🔗 1. Finite native addition and subtraction of a power of two, with finite source value a and an admitted exponent e; let m = 2e. smod_2exp_assign_r shall assign the unique value s ∈ [ − m ⁄ 2, m ⁄ 2) congruent to a modulo an integer multiple of m. This residue shall be exactly representable in F. If it is zero, its native sign shall equal the source's sign. In particular the positive half-modulus shall map to the negative half-modulus.

The result shall be V_EQ for every valid rounding request, including ordinary, strict and exactness requests. This exact relation shall not depend on native inexact-information availability or preexisting exception flags. The truncating remainder is exact, and either centering correction subtracts two representable magnitudes within a factor of two. Thus cancellation is exact and no rounded arithmetic protocol or inexact-status query is needed.

No particular hardware direction shall be required for these exact calculations. The operation shall preserve the hardware direction. Native backend setup, object validity, synchronization, destination/source aliases, source preservation, initialization independence and floating-point exception conditions shall follow 🔗 4. Rounding, result classes and state for finite native binary arithmetic. No bounded coefficient intermediate or irrational-precision setting shall limit the result.

Centered modular reduction needs a precise choice at the half-modulus boundary. The power-of-two modulus and exact cancellation permit the centered residue without approximation, including for nonintegral native inputs.

APPROVED
NUMERICS
IF_CPP, NATIVE_FP_AVAILABLE
Test, Analysis, Inspection

Use exact rational modular reduction at zero, both half-modulus boundaries and their immediate neighbors, exact modulus multiples, subnormals and large magnitudes. Cover both adjustment branches and the unadjusted branch, exponent limits, all available hardware directions, relation precision, exactness requests, signed zeros and raw/checked aliases.

src/checked_float_inlines.hh; src/Checked_Number_defs.hh and src/Checked_Number_inlines.hh; tests/floatingresiduesspec1.cc.

CPP
Public

Public header: <ppl.hh>; effective template instantiations for admitted same-format To and From types:

Result smod_2exp_assign_r(To& to, const From& from, unsigned exp,
                          Rounding_Dir dir);
SW_SPEC
4
PPL-SPEC-000509
Rounded nonnegative native residue modulo a power of two

For the source/destination types, finite source value a and admitted power-of-two modulus m in 🔗 3. Exact centered native residue modulo a power of two, umod_2exp_assign_r shall compute the unique mathematical residue u ∈ [0, m) congruent to a modulo an integer multiple of m. Let r = a − trunc(a ⁄ m)m.

When r ≥ 0, the operation shall store r exactly and return V_EQ for every valid request, without a hardware-direction prerequisite. When r < 0, it shall round and store r + m using the value, relation-precision, hardware-direction and exactness rules for native addition in 🔗 4. Rounding, result classes and state for finite native binary arithmetic. The returned relation shall compare the exact mathematical u with the stored value. A directed upward or delegated bound may equal m when u is not representable; the rounded value shall not be reduced again. ROUND_NOT_NEEDED shall require u to be exactly representable. If the mathematical residue is zero, the stored zero shall retain the source sign.

The operation shall preserve the hardware direction. Backend setup, live objects, synchronization, aliases, source preservation, initialization independence and floating-point exception conditions shall follow 🔗 4. Rounding, result classes and state for finite native binary arithmetic. No coefficient-range limit or irrational-precision setting shall restrict the calculation.

For a negative tiny source, the nonnegative residue can lie immediately below the modulus without being representable. Directed rounding must bound that mathematical residue and may therefore reach the modulus itself.

APPROVED
NUMERICS
IF_CPP, NATIVE_FP_AVAILABLE
Test, Analysis, Inspection

Compare with independent exact rational residues for both source signs, modulus multiples, half-modulus neighbors, negative subnormals and very large inputs. Check directed and delegated endpoint selection, strict and weak relations, admitted exactness requests, exponent limits, signed zeros, source/destination aliases, raw/checked forms and hardware preservation.

src/checked_float_inlines.hh; src/Checked_Number_defs.hh and src/Checked_Number_inlines.hh; tests/floatingresiduesspec1.cc.

CPP
Public

Public header: <ppl.hh>; effective template instantiations for admitted same-format To and From types:

Result umod_2exp_assign_r(To& to, const From& from, unsigned exp,
                          Rounding_Dir dir);