Parma Polyhedra Library requirements
C++ finite integer and rational conversion to native floating point
1. Supported exact integer and rational conversion to native floating storage UID: PPL-SPEC-000201 STATUS: APPROVED COMPONENT: NUMERICS APPLICABILITY: IF_CPP, NATIVE_FP_AVAILABLE VERIFICATION_METHODS: Test, Analysis, Inspection LANGUAGE: CPP VISIBILITY: Public RELATIONS (Parent): STATEMENT:

For each of float, double and long double whose corresponding PPL_SUPPORTED_FLOAT, PPL_SUPPORTED_DOUBLE or PPL_SUPPORTED_LONG_DOUBLE is nonzero, assign_r shall admit finite mpz_class and canonical finite mpq_class sources. The configured native binary format shall determine precision and finite range; it shall not inherit a bounded global-coefficient limit. Rational canonical form shall follow 🔗 1. Exact rational assignment from rational and integral sources.

When the source value is exactly representable as a finite destination value, the conversion shall assign that value and return V_EQ. This shall hold for all four base directions in 🔗 4. Rounding-direction intent, composition and inspection, with or without ROUND_STRICT_RELATION. Rational or integer zero shall produce a native zero; no distinct rational negative-zero value shall be implied.

The native destination adapter shall use Check_Overflow_Policy<T>. The _r conversion shall return its Result without invoking a policy handler or automatically throwing a numeric overflow exception. Computed infinities shall be representable in these supported native formats, and the outcomes in 🔗 5. Floating conversion overflow thresholds and computed-value classes shall not carry V_UNREPRESENTABLE.

The destination shall be a live assignable native object and the source shall remain unchanged. Callers shall prevent concurrent access to either object while another operation modifies it. No library initialization object, thread initialization or coefficient-constant stage shall be required. Configured native-format availability shall remain a prerequisite; a configuration disabling those supported types shall not promise these instantiations. For an available instantiation, conversion shall require no particular current FPU rounding direction and shall preserve that direction. Available resources shall limit temporary unbounded-integer computations.

RATIONALE:

An exact integer or rational conversion can construct a native binary value directly. Its correctness and relation need not depend on a host floating-point rounding mode or the global coefficient width.

INTERFACE:

Public header: <ppl.hh>; effective PPL template instantiations for a configured supported native floating-point type T:

Result assign_r(T& to, const mpz_class& from, Rounding_Dir dir);
Result assign_r(T& to, const mpq_class& from, Rounding_Dir dir);
VERIFICATION_CRITERIA:

Check zero, both signs, exact significand powers of two, maximum finite values, minimum normal values and subnormal values for every supported destination type. Compare exact integer-significand/power-of-two values independently of decimal conversion, require V_EQ for all valid directions and strict flags, preserve sources and check every supported hardware rounding mode. Compile a configuration with FPU control disabled without instantiating unavailable floating-point conversions.

SOURCE:

src/checked_float_inlines.hh; src/Checked_Number_defs.hh and src/Checked_Number_inlines.hh; tests/floatingconversionspec1.cc; tests/numericpublic1.cc.

2. Directed conversion to adjacent finite normal floating-point bounds UID: PPL-SPEC-000202 STATUS: APPROVED COMPONENT: NUMERICS APPLICABILITY: IF_CPP, NATIVE_FP_AVAILABLE VERIFICATION_METHODS: Test, Analysis, Inspection LANGUAGE: CPP VISIBILITY: Public RELATIONS (Parent): STATEMENT:

For source value a within the destination finite range, with |a| at least the smallest positive normal value and not exactly representable, base direction ROUND_DOWN shall assign the greatest representable destination value less than a; base direction ROUND_UP shall assign the least representable value greater than a. The destination types, sources and object prerequisites shall follow 🔗 1. Supported exact integer and rational conversion to native floating storage.

The downward call shall return V_GT and the upward call shall return V_LT. These shall be definite exact-to-computed relations as defined by 🔗 1. Numerical result classes and relation meanings, whether or not the request carries ROUND_STRICT_RELATION. Both bounds shall be finite and adjacent in the native value set. A source halfway between adjacent values shall follow the specified bound direction; no nearest-even tie rule shall replace it. Exact representable values shall instead follow 🔗 1. Supported exact integer and rational conversion to native floating storage.

RATIONALE:

A directed conversion selects an adjacent representable bound. Halfway inputs distinguish that obligation from nearest rounding, and an unbounded source can expose lost low significand bits precisely.

INTERFACE:

Public header: <ppl.hh>; effective PPL template instantiations for a configured supported native floating-point type T:

Result assign_r(T& to, const mpz_class& from, Rounding_Dir dir);
Result assign_r(T& to, const mpq_class& from, Rounding_Dir dir);
VERIFICATION_CRITERIA:

Construct exact rational quarter, half and three-quarter points between independently established adjacent native values, including either sign, binade boundaries and the largest finite pair. Check the two exact endpoint values and strict Result codes. Include integer halfway values just beyond the exact-integer precision threshold through both mpz and mpq source paths, without overflowing native oracle arithmetic.

SOURCE:

src/checked_float_inlines.hh; src/Checked_Number_defs.hh and src/Checked_Number_inlines.hh; tests/floatingconversionspec1.cc; tests/numericpublic1.cc.

3. Directed conversion in the subnormal and underflow range UID: PPL-SPEC-000203 STATUS: APPROVED COMPONENT: NUMERICS APPLICABILITY: IF_CPP, NATIVE_FP_AVAILABLE VERIFICATION_METHODS: Test, Analysis, Inspection LANGUAGE: CPP VISIBILITY: Public RELATIONS (Parent): STATEMENT:

Let δ be the smallest positive representable native subnormal value and let N be the smallest positive normal value. For a finite rational source with 0 < |a| < N, ROUND_DOWN shall assign the greatest native value not exceeding a, and ROUND_UP the least native value not less than a. Zero and every supported subnormal value shall be included when selecting these bounds. Source, destination and lifetime prerequisites shall follow 🔗 1. Supported exact integer and rational conversion to native floating storage.

An exactly representable subnormal shall return V_EQ. Otherwise the downward result shall return V_GT and the upward result V_LT, with or without a strict-relation flag. In particular, 0 < a < δ shall yield zero downward and δ upward;  − δ < a < 0 shall yield  − δ downward and zero upward. No sign-bit value shall be prescribed for a computed zero. The results shall be normal-class numerical bounds with no unrepresentable-storage flag.

RATIONALE:

Underflow must retain an outward bound even when a nonzero rational is smaller than every native nonzero value. Treating these cases as unconditional zero would lose the requested direction.

INTERFACE:

Public header: <ppl.hh>; effective PPL template instantiations for a configured supported native floating-point type T:

Result assign_r(T& to, const mpz_class& from, Rounding_Dir dir);
Result assign_r(T& to, const mpq_class& from, Rounding_Dir dir);
VERIFICATION_CRITERIA:

Check exact minimum and larger subnormals, fractions below the minimum, their signs, subnormal halfway points, and the pair straddling the largest subnormal and smallest normal value. Establish rational values with integer powers of two and independently compare the returned zero/subnormal endpoints, exact or strict relations and storage flags under all hardware rounding states.

SOURCE:

tests/floatrepresentationsspec1.cc; src/checked_float_inlines.hh; src/Checked_Number_defs.hh and src/Checked_Number_inlines.hh; tests/floatingconversionspec1.cc.

4. Delegated and exactness requests for floating-point conversion UID: PPL-SPEC-000204 STATUS: APPROVED COMPONENT: NUMERICS APPLICABILITY: IF_CPP, NATIVE_FP_AVAILABLE VERIFICATION_METHODS: Test, Analysis, Inspection LANGUAGE: CPP VISIBILITY: Public RELATIONS (Parent): STATEMENT:

For a finite source within the destination finite range, ROUND_IGNORE shall select the representable value obtained by rounding toward zero. An exact representable source shall return V_EQ. A positive inexact source shall return V_GT and a negative inexact source shall return V_LT. Adding ROUND_STRICT_RELATION shall preserve these definite relations. Destination types, source validity and object prerequisites shall follow 🔗 1. Supported exact integer and rational conversion to native floating storage.

ROUND_NOT_NEEDED shall require an exact source value representable as a finite destination value. With or without the strict flag, it shall assign that value and return V_EQ in assertion and nonassertion builds. Delegated requests outside the finite range shall follow 🔗 5. Floating conversion overflow thresholds and computed-value classes. These software conversions shall not infer their result from the hardware inexact flag or modify the current hardware rounding direction.

RATIONALE:

Delegation does not imply nearest rounding. For these integer-based conversions the toward-zero construction and exact remainder determine a definite relation without hardware inexact-state ownership.

INTERFACE:

Public header: <ppl.hh>; effective PPL template instantiations for a configured supported native floating-point type T:

Result assign_r(T& to, const mpz_class& from, Rounding_Dir dir);
Result assign_r(T& to, const mpq_class& from, Rounding_Dir dir);
VERIFICATION_CRITERIA:

Check positive and negative nonrepresentable rational values under ignore requests with and without strict relation, including subnormal and precision-boundary cases. Require toward-zero values and definite classifications. Exercise exact normal, subnormal, zero and endpoint values under both forms of no-rounding-needed request in both build modes.

SOURCE:

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

5. Floating conversion overflow thresholds and computed-value classes UID: PPL-SPEC-000205 STATUS: APPROVED COMPONENT: NUMERICS APPLICABILITY: IF_CPP, NATIVE_FP_AVAILABLE VERIFICATION_METHODS: Test, Analysis, Inspection LANGUAGE: CPP VISIBILITY: Public RELATIONS (Parent): STATEMENT:

For a supported destination type in 🔗 1. Supported exact integer and rational conversion to native floating storage, let p be its binary precision, emax its max_exponent, H = 2emax and M = (2p − 1)2emax − p, its largest finite value. Each source shall be a finite integer or canonical rational and satisfy the object prerequisites of 🔗 1. Supported exact integer and rational conversion to native floating storage. An optional strict-relation flag shall not change the following outcomes.

For M < a < H, ROUND_DOWN and ROUND_IGNORE shall assign M and return V_GT. ROUND_UP shall assign positive infinity and return V_LT_PLUS_INFINITY. For  − H < a <  − M, ROUND_UP and ROUND_IGNORE shall assign  − M and return V_LT; ROUND_DOWN shall assign negative infinity and return V_GT_MINUS_INFINITY. Computed infinity shall carry its corresponding infinity class, including when obtained by stepping past a finite endpoint.

For a ≥ H, ROUND_DOWN shall assign M and return V_GT_SUP; ROUND_UP and ROUND_IGNORE shall assign positive infinity and return V_LT_PLUS_INFINITY. For a ≤  − H, ROUND_UP shall assign  − M and return V_LT_INF; ROUND_DOWN and ROUND_IGNORE shall assign negative infinity and return V_GT_MINUS_INFINITY.

These numeric range outcomes shall be returned directly, without policy exception dispatch, and shall leave the destination usable. The native infinities shall be representable, so V_UNREPRESENTABLE shall be absent. ROUND_NOT_NEEDED shall exclude these out-of-range sources.

RATIONALE:

A finite inward rounding immediately beyond the endpoint differs from clamping a value whose unrestricted-exponent rounded result is itself outside the finite format. In every case the reported class must agree with a computed infinite bound.

INTERFACE:

Public header: <ppl.hh>; effective PPL template instantiations for a configured supported native floating-point type T:

Result assign_r(T& to, const mpz_class& from, Rounding_Dir dir);
Result assign_r(T& to, const mpq_class& from, Rounding_Dir dir);
VERIFICATION_CRITERIA:

Check integer and rational sources just beyond both finite endpoints, H and its negative, and larger magnitude values. Require inward endpoint values, outward infinity signs and exact Result classes/flags for every admitted direction. Check both signs and source paths around the finite-to-infinity successor/predecessor transition, then reassign destinations and preserve sources.

SOURCE:

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