Parma Polyhedra Library requirements
C++ finite checked scalar objects

C++ finite checked scalar objects

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

For T drawn from the eleven standard native integer types, mpz_class, mpq_class or a configured supported native floating format, Checked_Number<T, Policy> shall own one scalar value. Its policy shall admit that scalar's representation and the operations used below. Finite rational storage shall be canonical, with positive denominator.

Native_Number<T> shall have the truth value of Is_Native<T>::value. The default classification shall include the scalar families above and shall exclude bool, wide character types, checked wrappers and cv-qualified or reference types; it shall not strip qualifiers. Existing trait specializations shall continue to determine admission. This numeric classification shall not require Boolean equality or alter symbolic Variable comparisons. Native_Or_Checked_Number<T> shall have the truth value of Is_Native_Or_Checked<T>::value and classify raw scalars or checked wrappers. Its default classification shall exclude marker types and retain the same qualifier and trait-specialization rules. Numeric function templates shall use these classifications as constraints without requiring regular Boolean equality for unrelated symbolic types.

Default construction shall produce finite mathematical zero. Native floating zero shall initially have positive sign. Same-type copy construction and copy assignment shall preserve the source value, including a finite native floating zero's sign. The copied object's storage shall be independent of the source: changing or destroying one shall not change or invalidate the other. Same-object copy assignment shall preserve the value and return a reference to that object. Distinct-object copy assignment shall return a reference to the destination and preserve the source. Copying shall not invoke a policy conversion handler or require a rounding default.

A default-constructed or copied object shall be live, assignable and destructible. Copying shall require sufficient resources for the underlying scalar copy. Sources and existing assignment destinations shall be live; callers shall synchronize access overlapping modification of either object. No library initialization, coefficient constants or FPU rounding setup shall be required.

An owned scalar copy permits independently mutable numerical objects without changing the selected policy or invoking a numerical conversion.

APPROVED
NUMERICS
IF_CPP
Test, Analysis, Inspection

Check zero initialization, same-object assignment, distinct-object copy and assignment for all admitted scalar families and supported policies. Modify and destroy sources after copying, including large unbounded integers and nonintegral rationals, and confirm independent retained values. Cover native floating negative zero and boundary values. Use a recording policy to confirm that no handler or rounding default is consulted.

src/Checked_Number_defs.hh; src/Checked_Number_inlines.hh; src/Is_Native.hh; tests/commonhelpersspec1.cc; tests/checkedscalarsspec1.cc; tests/numericpublic1.cc.

CPP
Public

Public header: <ppl.hh>; members of Parma_Polyhedra_Library::Checked_Number<T, Policy>:

template <typename T>
concept Native_Number = bool(Is_Native<T>::value);
template <typename T>
concept Native_Or_Checked_Number = bool(Is_Native_Or_Checked<T>::value);

Checked_Number();
Checked_Number(const Checked_Number& source);
Checked_Number& operator=(const Checked_Number& source);
SW_SPEC
2
PPL-SPEC-000557

Finite value-converting Checked_Number<T, Policy> constructors shall convert their admitted native, unbounded integer, rational or checked scalar source with the numerical meaning and preconditions of the corresponding assign_r operation. An explicit direction shall select that conversion; a constructor without a direction shall use Policy::ROUND_DEFAULT_CONSTRUCTOR. A C-string constructor shall use the numeric input meaning of 🔗 1. Exact finite numeric token syntax through 🔗 4. Numeric text input into supported native floating destinations, with that explicit or default constructor direction. The string shall point to an accessible null-terminated token.

After conversion returns a Result, construction shall pass it once to Policy::handle_result. On normal handler return, the new object's stored value and any destination-value limitations shall be those of the conversion result. Handler exceptions shall propagate; a constructor that throws shall not produce a usable object. Numerical source objects shall remain unchanged.

Assignment from an admitted source of a different checked type or from a native, unbounded integer or rational source shall use assign_r with Policy::ROUND_DEFAULT_OPERATOR. It shall pass the result once to the handler and, on normal handler return, return a reference to the destination. Same-type copy assignment shall instead follow 🔗 1. Finite checked scalar storage and copying. A handler that throws shall not imply rollback of an assignment; guarantees for the surviving destination shall follow the numerical operation involved.

Required policy members shall follow 🔗 1. Operation-specific numerical policy capabilities. A finite source shall be admissible to its policy and the destination conversion; ROUND_NOT_NEEDED shall retain its exactness and intermediate-operation preconditions. Source lifetimes, resources, synchronization, shared-temporary serialization and any FPU prerequisites shall be those of the corresponding conversion or input contract. No additional library initialization shall be required by the wrapper.

The wrapper shall preserve the numerical contract of explicit conversions while adding the selected rounding default and result handling.

APPROVED
NUMERICS
IF_CPP
Test, Analysis, Inspection

Compare exact finite constructor and assignment values with literal integer and rational oracles across all admitted scalar destinations and representative native, GMP and checked sources. Include distinct source/destination policies, explicit and differing default directions, fractional input to integral storage, numeric strings and handler exceptions. Verify handler call counts, returned references, source preservation and independence after later mutation. Use the existing conversion contracts for range and inexactness outcomes.

src/Checked_Number_defs.hh; src/Checked_Number_inlines.hh; tests/checkedscalarsspec1.cc; tests/numericpublic1.cc.

CPP
Public

Public header: <ppl.hh>; representative admitted members of Parma_Polyhedra_Library::Checked_Number<T, Policy>:

Checked_Number(int source, Rounding_Dir dir);
Checked_Number(int source);
Checked_Number(const mpz_class& source, Rounding_Dir dir);
Checked_Number(const mpq_class& source, Rounding_Dir dir);
Checked_Number(const char* source, Rounding_Dir dir);
Checked_Number(const char* source);
template <typename From, typename From_Policy>
Checked_Number(const Checked_Number<From, From_Policy>& source,
               Rounding_Dir dir);
template <typename From, typename From_Policy>
explicit Checked_Number(const Checked_Number<From, From_Policy>& source);
template <typename From>
Checked_Number& operator=(const From& source);

The corresponding admitted scalar constructor overloads shall include the remaining standard native integer types, configured supported native floating formats and default-direction unbounded integer and rational forms.

SW_SPEC
3
PPL-SPEC-000558
PPL-SPEC-000558
Checked scalar storage references and value conversion

For a live finite Checked_Number<T, Policy> admitted by 🔗 1. Finite checked scalar storage and copying, mutable raw_value() and the corresponding free raw_value shall return references to the same owned T object. Their const overloads shall return const references to that object without copying or changing its value. A reference shall remain associated with the same storage object until its owner is destroyed; changing the owned value shall not rebind it. Callers that modify raw storage shall maintain its representation and policy prerequisites, including canonical rational form.

The conversion shall participate only when Policy::convertible is a constant expression with a true Boolean value. A missing, false or nonconstant flag shall leave default construction and raw access available without advertising this conversion. Policy access granted to the checked class shall remain usable for this decision.

Where conversion is enabled, conversion to T shall return an independent value copy, preserving the finite value and native floating zero sign. Altering that copy shall not alter the checked object. Raw access and this value conversion shall not invoke a result handler or numerical rounding. The policy restrictions of 🔗 1. Operation-specific numerical policy capabilities shall apply to underlying value conversion. No initialization or FPU rounding setup shall be required; callers shall synchronize access overlapping modification of the owner.

Direct storage access permits common numerical adapters to operate on the owned scalar, while permitted value conversion preserves ownership.

APPROVED
NUMERICS
IF_CPP
Test, Analysis, Inspection

Check exact reference types and address identity of all four raw access forms. Retain references across assignments and swaps, mutate through each mutable reference and confirm the checked value changes. For convertible policies, mutate converted copies and confirm independence, including GMP allocation and native floating negative zero. Confirm no handler calls and unchanged FPU rounding state. Reject missing, false and nonconstant conversion flags in conversion traits; retain default construction and raw access. Admit constant true integral flags and flags accessible through checked-class friendship.

src/Checked_Number_defs.hh; src/Checked_Number_inlines.hh; tests/checkedscalarsspec1.cc; tests/numericpublic1.cc; tests/numericpoliciesspec1.cc.

CPP
Public

Public header: <ppl.hh>; members and related functions in PPL:

T& Checked_Number<T, Policy>::raw_value();
const T& Checked_Number<T, Policy>::raw_value() const;
// Participates only for a constant true Policy::convertible flag.
Checked_Number<T, Policy>::operator T() const;
template <typename T, typename Policy>
T& raw_value(Checked_Number<T, Policy>& source);
template <typename T, typename Policy>
const T& raw_value(const Checked_Number<T, Policy>& source);
SW_SPEC
4
PPL-SPEC-000559
PPL-SPEC-000559
Checked scalar value swap

For live Checked_Number<T, Policy> objects with the same scalar type and policy and admitted finite or special values, swap(x, y) shall exchange their stored values, including native floating zero signs and admitted infinity signs. An admitted NaN shall remain NaN; ordered equality shall not be required to compare it with its former value. Policies shall remain the template policies of their respective objects. Same-object swap shall preserve the value. Existing raw references shall continue to refer to their original owned storage objects and shall observe the exchanged values.

Swap shall not perform numerical conversion, consult a rounding default or invoke a result handler. It shall require the scalar's swap resources and representation prerequisites, and shall preserve both objects' assignability and destructibility on successful return. Callers shall synchronize access overlapping modification of either object. No initialized library state or FPU rounding setup shall be required.

Exchanging owned numerical values shall not introduce an additional rounding or result-handling decision.

APPROVED
NUMERICS
IF_CPP
Test, Analysis, Inspection

Exchange distinct positive, negative, zero, boundary and dynamically allocated scalar values. Test same-object swap, repeated swap, retained raw references, independent later mutation and native floating signed zero. Use policies without rounding defaults or handlers and a recording policy to verify that swap requires neither facility.

src/Checked_Number_defs.hh; src/Checked_Number_inlines.hh; tests/checkedscalarsspec1.cc; tests/numericpublic1.cc.

CPP
Public

Public header: <ppl.hh>; related function in PPL:

template <typename T, typename Policy>
void swap(Checked_Number<T, Policy>& x,
          Checked_Number<T, Policy>& y);
SW_SPEC
5
PPL-SPEC-000560
PPL-SPEC-000560
Checked scalar memory-size inspection

For a live finite checked scalar admitted by 🔗 1. Finite checked scalar storage and copying, external_memory_in_bytes(x) shall report the same memory-size metric as that query applied to the owned scalar x.raw_value(). total_memory_in_bytes(x) shall likewise report the corresponding owned scalar's total-size metric. For native integer and supported native floating storage, external size shall be zero and total size shall be sizeof(T). For GMP integer and rational storage, the metric shall include the owned scalar's allocated limb storage according to the underlying memory queries. It shall describe allocated storage, rather than only significant digits.

Both queries shall preserve the object and any retained raw references and shall neither invoke policy handlers nor perform numerical rounding. Results shall fit memory_size_type. Callers shall synchronize inspection with modification of the inspected object. No library initialization or FPU rounding setup shall be required.

The numerical wrapper shall expose the storage metric of its owned scalar without adding a separate allocation or changing the represented value.

APPROVED
NUMERICS
IF_CPP
Test, Analysis, Inspection

Check exact native sizes and zero external allocation for every standard integer and supported floating type. For GMP integers and rationals, compare wrapper and owned-scalar metrics before and after growing both numerator and denominator storage, copying and swapping. Confirm total size includes the scalar object and its external allocation, preserved numerical values and references, and absence of policy handling or rounding changes.

src/Checked_Number_defs.hh; src/Checked_Number_inlines.hh; tests/checkedscalarsspec1.cc; tests/numericpublic1.cc.

CPP
Public

Public header: <ppl.hh>; related functions in PPL:

template <typename T, typename Policy>
memory_size_type total_memory_in_bytes(const Checked_Number<T, Policy>& x);
template <typename T, typename Policy>
memory_size_type external_memory_in_bytes(const Checked_Number<T, Policy>& x);
SW_SPEC
6
PPL-SPEC-001197
PPL-SPEC-001197
Complete checked-wrapper placement construction without a handler

For an admitted call to the result-returning free construct function with To = Checked_Number<T, Policy>, the destination shall denote suitably aligned storage sufficient for that complete wrapper, with no live complete wrapper occupying it. T shall be an admitted native integer, configured native floating format, mpz_class or mpq_class. A numerical source shall be live and initialized; a typed special marker shall have its existing marker meaning. Source storage shall not overlap the unconstructed destination. The selected source/destination policies, scalar conversion and rounding request shall satisfy their existing numerical, representation, resource, initialization, FPU and synchronization prerequisites.

On normal return, a complete destination wrapper and its owned scalar shall have begun their lifetimes. The wrapper shall admit destruction and subsequent supported assignment. The represented result and returned Result shall have the selected checked conversion or typed-special assignment meaning. A failure or unrepresentable result shall not promise a numerical payload that its result and policy do not otherwise define. The source shall be preserved. The free function shall apply its existing exactness-request translation and result check once, without invoking a policy result handler or requiring a constructor rounding default. Both deduced calls and calls that explicitly specify To and From shall have this meaning.

If conversion throws after an owned class scalar has been initialized, ordinary constructor unwinding shall destroy that scalar. No complete destination wrapper is returned from the failed construction. This rule shall not imply an allocation rollback guarantee for the containing row or a live wrapper that the caller must destroy after a failed constructor. Raw native/GMP construction routes and ordinary public wrapper constructors shall retain their existing contracts; in particular, this no-handler function shall not replace the result handling of an ordinary converting constructor.

A raw scalar subobject construction does not itself start the enclosing non-implicit-lifetime checked wrapper. Constructing the complete wrapper centrally permits all free construction callers, including upward DB-row conversion, to use the intended wrapper type. A private no-handler entry keeps result-returning construction distinct from an ordinary converting constructor and gives initialized class members language-provided cleanup.

APPROVED
NUMERICS
IF_CPP
Test, Analysis, Inspection

1. Exercise numerical and typed-special free construction in aligned raw wrapper storage, both with deduction and explicit two-template arguments, using policies without rounding defaults or an available result handler. Check the returned relation/class, source preservation, supported replacement and destruction. Include native, MPZ and canonical MPQ scalar families. 2. Inspect the complete wrapper placement-new and the private constructor's live member access, one request translation and one result check. Verify that no destination member function is called before complete wrapper construction and that initialized class scalar cleanup is supplied on constructor failure. 3. Check upward row conversion with fresh coherent normal and fallback storage profiles, preserving numerical values and sources without an extra conversion handler. Check raw-native and raw-GMP construction results and their independent replacement and destruction behavior under their existing contracts.

src/Checked_Number_defs.hh; src/Checked_Number_inlines.hh; src/DB_Row_templates.hh; tests/checkedscalarsspec1.cc; tests/dbrowownedhistories1.cc.

CPP
Public

Public header: <ppl.hh>; free functions in PPL, with the admitted destination restriction above. Existing enable conditions and overload selection remain.

template <typename To, typename From>
Result construct(To& destination, const From& source, Rounding_Dir dir);

Internal private tagged construction and its checked-destination access helper implement the complete-object lifetime. They are not additional public constructors or new conversion-policy defaults.