Parma Polyhedra Library requirements
C++ finite scalar conversion to unbounded integer storage

C++ finite scalar conversion to unbounded integer storage

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-000261

assign_r shall admit every native integral source type and Checked_Number<T, Check_Overflow_Policy<T>> source type in 🔗 1. Exact conversion between native and checked integral scalars, as well as a finite mpz_class source. The destination shall be mpz_class independently of the configured Coefficient alias. For each admitted source integer it shall assign the exact value and return V_EQ under all four base directions in 🔗 4. Rounding-direction intent, composition and inspection, with or without the strict-relation flag. This shall include all native signed and unsigned endpoints. An mpz_class source may be the destination itself, preserving its entry integer value.

The destination shall be live and assignable. A distinct source shall remain unchanged, and later destination mutation shall not affect a distinct source. Callers shall prevent concurrent access to an object while another operation modifies it. No library initialization object, thread initialization or coefficient-constant stage shall be required. This operation shall impose no fixed-width integer range bound; available resources shall limit storage. It shall return the conversion Result without policy-handler dispatch.

An unbounded integer destination remains available even when the global coefficient alias is bounded. Embedding native endpoints must not pass through a narrower coefficient value.

APPROVED
NUMERICS
IF_CPP, SCALAR_MPZ
Test, Analysis, Inspection

Check all eleven native types and their checked wrappers at zero, both signs and full signed/unsigned endpoints. Check multi-limb mpz assignment, self-aliasing, independent copying and every direction/strict flag with exact status. Run in every global coefficient profile without initialization stages.

src/checked_mpz_inlines.hh; src/Checked_Number_defs.hh and src/Checked_Number_inlines.hh; tests/unboundedintegerconversionspec1.cc; tests/numericpublic1.cc.

CPP
Public

Public header: <ppl.hh>; effective PPL template instantiation for the admitted source types:

Result assign_r(mpz_class& to, const From& from, Rounding_Dir dir);
SW_SPEC
2
PPL-SPEC-000262

For a finite canonical mpq_class source with value a, assign_r into mpz_class with base direction ROUND_DOWN shall assign ⌊a⌋; base ROUND_UP shall assign ⌈a⌉. Rational canonical form shall follow 🔗 1. Exact rational assignment from rational and integral sources. The destination shall not designate the source rational's numerator or denominator object or overlap their storage. There shall be no fixed-width integer range bound.

Without ROUND_STRICT_RELATION, the downward request shall return V_GE and the upward request V_LE. These shall permit equality and shall not promise that an integral source has been classified as exact. With that flag, an integral source shall return V_EQ; a nonintegral source shall return V_GT downward and V_LT upward, with the relation orientation in 🔗 1. Numerical result classes and relation meanings.

No particular current hardware rounding direction shall be required and the current direction shall remain unchanged. Object validity, synchronization, source preservation, initialization independence and resource conditions shall follow 🔗 1. Exact native integral and unbounded integer assignment to mpz storage. This conversion shall require no shared temporary pool.

A rational quotient can be rounded exactly using integer numerator and denominator operations. A weak result relation is a deliberate classification unless strict relation determination was requested.

APPROVED
NUMERICS
IF_CPP, SCALAR_MPZ
Test, Analysis, Inspection

Use literal signed quotients and independent unbounded quotient/remainder calculations for exact integers, proper fractions, halves and large numerator/denominator values. Require the documented weak classifications without strict flags and definite classifications with them. Repeat under all hardware modes, preserving canonical source components.

src/checked_mpz_inlines.hh; src/Checked_Number_defs.hh and src/Checked_Number_inlines.hh; tests/unboundedintegerconversionspec1.cc; tests/numericpublic1.cc.

CPP
Public

Public header: <ppl.hh>; effective PPL template instantiation for the admitted source types:

Result assign_r(mpz_class& to, const From& from, Rounding_Dir dir);
SW_SPEC
3
PPL-SPEC-000263
PPL-SPEC-000263
Delegated and exactness rational conversion to an unbounded integer

For a finite canonical mpq_class source with value a, ROUND_IGNORE shall assign trunc(a) toward zero to the mpz_class destination. Without a strict flag it shall return V_LGE. ROUND_NOT_NEEDED shall require an integral canonical source, whose denominator is one, and shall assign that exact integer. Without a strict flag it shall return V_EQ in an assertion-enabled build and may return lazy V_LGE in a build defining NDEBUG, following 🔗 7. Internal no-rounding-needed request and result checking.

With ROUND_STRICT_RELATION, the delegated conversion shall report the definite relation: V_GT for a positive nonintegral source, V_LT for a negative nonintegral source, and V_EQ for an integral source. A strict no-rounding-needed request shall retain the integral-source precondition and return V_EQ.

Object, synchronization, source-preservation, resource and initialization conditions shall follow 🔗 1. Exact native integral and unbounded integer assignment to mpz storage. The rational-component nonaliasing condition in 🔗 2. Directed canonical rational conversion to an unbounded integer shall apply. No particular hardware rounding direction or shared temporary pool shall be required. The hardware direction shall remain unchanged and no fixed-width range limit shall apply.

A delegated result may be lazy while still holding the correct truncated integer. An exactness request has an integral-source precondition, and a strict request resolves the otherwise weak relation.

APPROVED
NUMERICS
IF_CPP, SCALAR_MPZ
Test, Analysis, Inspection

Check signed truncation using exact numerator/denominator answers, integral no-rounding-needed inputs in both build modes, and definite relations for strict delegated and exactness requests. Exercise large values, zero and proper fractions under all hardware modes without initialization stages.

src/checked_mpz_inlines.hh; src/Checked_Number_defs.hh and src/Checked_Number_inlines.hh; tests/unboundedintegerconversionspec1.cc.

CPP
Public

Public header: <ppl.hh>; effective PPL template instantiation for the admitted source types:

Result assign_r(mpz_class& to, const From& from, Rounding_Dir dir);
SW_SPEC
4
PPL-SPEC-000264

The source shall be a finite float, double or long double whose corresponding PPL_SUPPORTED_FLOAT, PPL_SUPPORTED_DOUBLE or PPL_SUPPORTED_LONG_DOUBLE is nonzero. Its meaning shall be the exact represented binary value a. ROUND_DOWN shall assign ⌊a⌋ to mpz_class and ROUND_UP shall assign ⌈a⌉, with no fixed-width integer range restriction.

For float and double, a nonintegral source shall require the hardware rounding direction to be upward. An integral source shall return V_EQ; a nonintegral downward result shall return V_GT and an upward result V_LT, with or without the strict-relation flag. Exact integral inputs shall not require a particular current hardware direction.

For long double, no particular hardware direction shall be required. Without the strict flag the downward request shall return V_GE and the upward request V_LE. With the flag it shall return V_EQ for an integral source, V_GT for an inexact downward result and V_LT for an inexact upward result. This classification shall follow the exact rational route in 🔗 2. Directed canonical rational conversion to an unbounded integer, including when the native long double format has the same precision as double.

Object validity, source preservation, resource limits and initialization independence shall follow 🔗 1. Exact native integral and unbounded integer assignment to mpz storage. Current hardware rounding direction shall be preserved. The long double route shall use a lazily owned rational temporary; in a non-thread-safe configuration, concurrent calls sharing that temporary machinery shall be serialized, even on distinct argument objects. In a thread-safe configuration its pool shall belong to the calling thread. Unavailable native source types shall not be instantiated.

All finite floating-point values have exact dyadic rational meanings and therefore admit unbounded integer bounds. Different native source routes may expose different relation precision without changing the integer result.

APPROVED
NUMERICS
IF_CPP, SCALAR_MPZ, NATIVE_FP_AVAILABLE
Test, Analysis, Inspection

For each configured source format, derive exact significand/power-of-two oracles for positive and negative fractions, subnormals, precision boundaries and finite maxima. Check strict and nonstrict result classifications separately for float/double versus long double. Use upward hardware direction for nonintegral float/double and every hardware direction for the rational long-double route; preserve source values and direction state.

src/checked_mpz_inlines.hh; src/Checked_Number_defs.hh and src/Checked_Number_inlines.hh; tests/unboundedintegerconversionspec1.cc.

CPP
Public

Public header: <ppl.hh>; effective PPL template instantiation for the admitted source types:

Result assign_r(mpz_class& to, const From& from, Rounding_Dir dir);
SW_SPEC
5
PPL-SPEC-000265
PPL-SPEC-000265
Delegated finite floating-point conversion and exactness into mpz storage

For the configured finite source types in 🔗 4. Directed finite native floating-point conversion to mpz storage, ROUND_IGNORE shall assign trunc(a) toward zero to mpz_class. Without a strict flag it shall return V_LGE. ROUND_NOT_NEEDED shall require the represented source value to be an integer and shall assign that exact value. Without a strict flag it shall return V_EQ in an assertion-enabled build and may return lazy V_LGE in a build defining NDEBUG, following 🔗 7. Internal no-rounding-needed request and result checking.

With ROUND_STRICT_RELATION, delegated conversion shall determine V_GT for a positive nonintegral source, V_LT for a negative nonintegral source, and V_EQ for an integral source. A strict no-rounding-needed request shall retain its integral-source precondition and return V_EQ.

These requests shall require no particular current hardware rounding direction and shall preserve that direction. Object validity, source preservation, initialization independence, resource limits, availability and long-double temporary-pool ownership shall follow 🔗 4. Directed finite native floating-point conversion to mpz storage. No finite source shall overflow a fixed integer range or be classified as an infinite result merely because the selected global coefficient profile is bounded.

An unbounded integer conversion avoids an artificial coefficient-width range failure. Delegated truncation and a strict relation request remain distinct guarantees for every native floating-point source route.

APPROVED
NUMERICS
IF_CPP, SCALAR_MPZ, NATIVE_FP_AVAILABLE
Test, Analysis, Inspection

Check exact and nonintegral signed dyadic values, zero, subnormals, native finite maxima and values beyond every bounded coefficient width. Verify lazy unflagged truncation, both build modes for exactness requests, definite strict relations, source preservation and unchanged hardware direction under all supported modes.

src/checked_mpz_inlines.hh; src/Checked_Number_defs.hh and src/Checked_Number_inlines.hh; tests/unboundedintegerconversionspec1.cc.

CPP
Public

Public header: <ppl.hh>; effective PPL template instantiation for the admitted source types:

Result assign_r(mpz_class& to, const From& from, Rounding_Dir dir);
SW_SPEC
6
PPL-SPEC-001196
Finite native floating-point placement construction of an unbounded integer

The source type F shall be float or double with its corresponding PPL_SUPPORTED_FLOAT or PPL_SUPPORTED_DOUBLE nonzero. The source shall be a live finite value with exact represented binary value a. The selected source and destination policies shall admit these finite values and provide the capabilities used by the native-to-mpz_class conversion. No policy rounding default or result handler shall be required.

The destination reference shall designate writable storage of at least sizeof(mpz_class) bytes, correctly aligned for mpz_class, with no live mpz_class occupying it. The storage shall be available for placement construction without ending an object lifetime that the caller must preserve. The source shall not overlap that storage. Before placement construction begins the destination glvalue shall be used only in ways permitted for storage outside an object's lifetime; it shall not be read as a live mpz_class. On normal return exactly one live mpz_class shall occupy the storage. Its caller shall arrange exactly one destruction of that object before releasing or reusing the storage.

ROUND_DOWN shall construct ⌊a⌋ and ROUND_UP shall construct ⌈a⌉. These requests shall return V_EQ for an integral source, otherwise V_GT downward or V_LT upward, with or without ROUND_STRICT_RELATION. ROUND_IGNORE shall construct trunc(a) and return V_LGE without the strict flag. With that flag it shall return V_EQ for an integral source, V_GT for a positive nonintegral source, and V_LT for a negative nonintegral source.

A raw kernel ROUND_NOT_NEEDED request shall require an integral source, construct its exact integer value and return V_LGE without the strict flag or V_EQ with it. A caller-translated ROUND_CHECK exactness request shall retain that integral-source precondition and return V_EQ. The public numerical construct adapter shall perform the direction and exactness-check translation in 🔗 7. Internal no-rounding-needed request and result checking before invoking this kernel. The kernel shall return Result without policy-handler dispatch.

A directed request on a nonintegral source shall require upward hardware rounding. Integral sources and delegated truncation shall require no particular current direction. Every call shall preserve the current hardware rounding direction. Floating-point exceptions shall be nontrapping; accrued exception flags shall be unspecified. Available GMP resources shall be required, without a fixed-width integer limit. No library/thread initialization owner, coefficient-constant stage or shared temporary pool shall be required. Callers shall synchronize storage use against concurrent access. Resource failure shall not be a successful result; no universal object-lifetime or storage-rollback guarantee shall be imposed after an abnormal exit.

Placement construction begins an integer object's lifetime, whereas assignment requires an already live object. The numerical result and its relation must remain consistent with the requested rounding and exactness conventions without introducing a policy-handler decision.

APPROVED
NUMERICS
IF_CPP, SCALAR_MPZ, NATIVE_FP_AVAILABLE
Test, Analysis, Inspection

Use correctly aligned raw storage and the admitted public numerical construct route or the internal kernel. After a successful construction, obtain the live object using the applicable C++ lifetime rules, compare it with an independent exact rational oracle, and destroy it exactly once. Check both source formats, both signs, zeros, nonintegral dyadic values, subnormals, finite maxima and exact integral values. Exercise all admitted directions and strict flags, including raw kernel exactness and the public adapter's debug/release translation. Check unchanged source values and hardware direction, definite strict relations, lazy unflagged relations, zero handler calls, and independence from the configured coefficient width. Do not inspect an unconstructed object or infer a general failure rollback.

src/checked_mpz_inlines.hh; src/checked_ext_inlines.hh; src/Checked_Number_defs.hh; src/Checked_Number_inlines.hh; tests/unboundedintegerconversionspec1.cc.

CPP
Internal

Internal header: src/checked_mpz_inlines.hh; namespace Parma_Polyhedra_Library::Checked; admitted F and policy types above:

template <typename To_Policy, typename From_Policy, typename F>
Result construct_mpz_float(mpz_class& to, const F& from,
                           Rounding_Dir dir);