Parma Polyhedra Library requirements
C++ scalar machine ASCII persistence

C++ scalar machine ASCII persistence

1. Exact scalar ASCII persistence
UID: PPL-SPEC-000571
STATUS: APPROVED
COMPONENT: NUMERICS
APPLICABILITY: IF_CPP
VERIFICATION_METHODS: Test, Analysis, Inspection
LANGUAGE: CPP
VISIBILITY: Public
RELATIONS (Parent):
STATEMENT:

For the eleven standard native integer types, mpz_class, mpq_class and their Checked_Number wrappers, ascii_dump shall write a finite scalar's exact mathematical value in the compatible decimal representation. Integral values, including raw char, signed char and unsigned char, shall be represented numerically. A canonical rational shall use its exact integer or numerator/denominator representation.

Under compatible scalar type, policy, locale and stream-format conditions, ascii_load of a complete representation emitted for an admitted finite value shall return true and restore that value. All representable native integer values shall belong to the round-trip scope. Distinct successive records separated by whitespace shall be reloadable in order without consuming another record's value. The stream shall remain positioned after the loaded numeric token. Canonical finite GMP rational producer records shall restore canonical finite rational storage.

The producer and consumer shall use classic-locale ordinary decimal numeric formatting, with no field padding. Checked exact input shall require the policy capabilities of 🔗 6. Checked numeric stream policy integration, including a default input direction compatible with the exact stored value and a result handler that permits its returned result. Checked output shall require a result handler. Underlying scalar storage shall be live and finite; rational producer values and compatible rational records shall be canonical with positive denominator. The corresponding mathematical input and output semantics and relevant serialization prerequisites shall follow 🔗 1. Exact finite numeric token syntax through 🔗 6. Checked numeric stream policy integration for checked stream operations. These numeric-text parser rules shall not replace the ordinary GMP extraction rules for raw GMP destinations. Successful raw GMP rational extraction shall not by itself promise canonicalization or a nonzero denominator: for example, 2/4 and 1/0 may be accepted as those numerator/denominator representations. Subsequent numerical use shall first meet its canonicalization and nonzero- denominator prerequisites.

RATIONALE:

An exact numerical representation shall preserve every admitted integer or canonical rational value when scalar records are embedded in larger saved objects.

INTERFACE:

Public header: <ppl.hh>; effective instantiations in PPL:

void ascii_dump(std::ostream& stream, const Number& value);
bool ascii_load(std::istream& stream, Number& value);

Number shall be an admitted exact scalar type stated above.

VERIFICATION_CRITERIA:

Round-trip literal positive, negative, zero and endpoint values for every admitted integer type and checked form. Include raw and checked character values that coincide with whitespace, and sequential-record framing. Check large GMP integers and nonintegral canonical rationals with independently known values. Verify the required policy capabilities, destination reuse, retained following records and no coefficient-width restriction.

SOURCE:

src/Checked_Number_defs.hh; src/Checked_Number_templates.hh; tests/scalarasciispec1.cc; tests/numberinput1.cc.

2. Finite floating scalar ASCII byte records
UID: PPL-SPEC-000572
STATUS: APPROVED
COMPONENT: NUMERICS
APPLICABILITY: IF_CPP, NATIVE_FP_AVAILABLE
VERIFICATION_METHODS: Test, Analysis, Inspection
LANGUAGE: CPP
VISIBILITY: Public
RELATIONS (Parent):
STATEMENT:

For a configured supported native floating type or its checked wrapper, ascii_dump shall emit exactly two hexadecimal digits for each byte of the source object's representation, in increasing memory-address order. Leading zero nibbles shall be included. The byte token shall be followed by one space and a nonempty parenthesized display token. The byte token shall be authoritative for reload; the display shall be supplementary.

The source shall be live and finite, including either signed zero, subnormal values and finite range endpoints. Producer and consumer shall use the same scalar or checked type, object size and ABI. In particular, the record shall not promise interchange between different floating formats or checked object types. The producer stream shall use the classic locale, right adjustment, no base prefix and ordinary numeric display formatting. Checked display output shall require a policy result handler under 🔗 6. Checked numeric stream policy integration. On normal return, original formatting flags shall be restored; byte emission shall select a zero fill character. The source value and hardware rounding direction shall remain unchanged. No library initialization or FPU rounding setup shall be required; available resources and nontrapping floating exceptions shall be prerequisites.

RATIONALE:

Object bytes preserve finite floating values, signed zero and subnormals independently of the precision used for a supplementary human-readable number.

INTERFACE:

Public header: <ppl.hh>; effective instantiation in PPL:

void ascii_dump(std::ostream& stream, const Number& value);

Number shall be a configured supported native floating type or its checked wrapper with the stated output capability.

VERIFICATION_CRITERIA:

Compare the emitted byte token against independently inspected unsigned object bytes for each supported native and checked floating format. Include signed zero, opposite signs, subnormal and normal boundaries and maximum finite magnitudes. Vary display precision without changing the byte token; check exact token width, original formatting flags, zero fill selection, source preservation and unchanged hardware direction.

SOURCE:

src/Checked_Number_defs.hh; src/Checked_Number_templates.hh; tests/scalarasciispec1.cc; tests/numberinput1.cc.

3. Finite floating scalar ASCII reload and framing
UID: PPL-SPEC-000573
STATUS: APPROVED
COMPONENT: NUMERICS
APPLICABILITY: IF_CPP, NATIVE_FP_AVAILABLE
VERIFICATION_METHODS: Test, Analysis, Inspection
LANGUAGE: CPP
VISIBILITY: Public
RELATIONS (Parent):
STATEMENT:

For the compatible finite object records of 🔗 2. Finite floating scalar ASCII byte records, ascii_load shall read a hexadecimal byte token of exactly twice the destination object's size. Each hexadecimal letter shall be accepted in upper or lower case. It shall restore the bytes to the corresponding memory positions and require a following nonempty whitespace-delimited token whose first character is ( and last character is ). There shall be at least one character between the parentheses. On successful reload it shall return true and preserve the represented finite value and zero sign. The contents between parentheses shall be discarded; they shall not override or be required to numerically agree with the byte token. A following record shall remain available for a subsequent load.

An absent or wrong-length byte token, a nonhexadecimal byte digit, a missing display token or a display token without that nonempty parenthesized framing shall return false when the stream's exception mask permits normal return. A false return shall not require failbit if a lexical token was successfully extracted before the record-shape check failed. The destination may already have been changed; rollback shall not be promised.

The destination shall be live, and finite records shall encode a valid finite object of that same type and ABI. Resetting storage after a rejected record shall precede any numerical use that requires a valid finite representation. Checked floating reload shall require a policy providing the input-stream capabilities of 🔗 6. Checked numeric stream policy integration, including ROUND_DEFAULT_INPUT and handle_result. Successful byte reload shall restore the representation directly without applying that numerical rounding default or invoking the handler. No library initialization or FPU rounding setup shall be required, and the hardware direction shall remain unchanged.

RATIONALE:

The saved bytes determine the restored number. Structural validation and explicit failure-state limits permit composite readers to detect truncated or malformed records without assuming transactional reload.

INTERFACE:

Public header: <ppl.hh>; effective instantiation in PPL:

bool ascii_load(std::istream& stream, Number& value);

Number shall be a configured supported native floating type or its checked wrapper with the stated input-stream capabilities.

VERIFICATION_CRITERIA:

Reload independently generated compatible byte records in both hex letter cases and compare object bytes, finite values and zero signs. Replace the display contents with other nonempty text to verify byte authority. Test all byte-length and digit rejection stages, missing or malformed display tokens, sequential records and destination reset/reuse. Use a recording policy to confirm that successful checked floating byte reload invokes no handler.

SOURCE:

src/Checked_Number_defs.hh; src/Checked_Number_templates.hh; tests/scalarasciispec1.cc; tests/numberinput1.cc.

PPL-SPEC-000574
4. Scalar ASCII stream delivery and failure handling
UID: PPL-SPEC-000574
STATUS: APPROVED
COMPONENT: NUMERICS
APPLICABILITY: IF_CPP
VERIFICATION_METHODS: Test, Analysis, Inspection
LANGUAGE: CPP
VISIBILITY: Public
RELATIONS (Parent):
STATEMENT:

Scalar ASCII persistence shall use ordinary stream delivery state and the stream's selected exception mask. ascii_dump shall return no delivery status; normal return shall not imply that the output stream accepted every character. ascii_load shall return false when a required formatted extraction fails and no enabled exception interrupts the operation. Exact checked scalar loads shall retain the policy exception behavior of 🔗 6. Checked numeric stream policy integration. Exceptions enabled by the stream mask and policy handler exceptions shall propagate. Stream-buffer exception handling shall follow the underlying formatted stream operation.

Producer source values shall remain unchanged. On failed input, destination storage and stream position may already have changed; callers shall reset an affected destination and clear or replace the stream before retrying. Native and GMP scalar storage shall remain destructible and assignable; no earlier numerical value shall be promised. After a successful compatible retry the destination shall have the newly loaded finite value.

Callers shall synchronize stream and object access overlapping modification. The selected scalar's allocation and representation prerequisites shall apply. No coefficient-constant stage or library initialization shall be introduced by scalar persistence. Checked exact numeric parsing shall retain its shared-temporary serialization requirements from 🔗 3. Numeric text input into integral destinations. Floating byte records shall retain the finite/type/ABI prerequisites of 🔗 2. Finite floating scalar ASCII byte records and 🔗 3. Finite floating scalar ASCII reload and framing.

RATIONALE:

Composite persistence needs observable delivery failures and usable retry rules without a universal rollback guarantee.

INTERFACE:

Public header: <ppl.hh>; effective instantiations in PPL:

void ascii_dump(std::ostream& stream, const Number& value);
bool ascii_load(std::istream& stream, Number& value);

Number shall be an admitted exact or finite floating scalar type from 🔗 1. Exact scalar ASCII persistence through 🔗 3. Finite floating scalar ASCII reload and framing.

VERIFICATION_CRITERIA:

Use bidirectional streams, preexisting failure states, truncation, returning and throwing stream buffers and enabled fail/bad exception masks. Confirm false returns or the precise stream/policy exceptions as appropriate, source preservation, explicit destination reset and successful retry. Distinguish a shape-check false return from an extraction failure and an output stream's normal return with bad state.

SOURCE:

src/Checked_Number_defs.hh; src/Checked_Number_templates.hh; tests/scalarasciispec1.cc; tests/numberinput1.cc.