Parma Polyhedra Library requirements
C++ mathematical numeric text input and output
1. Exact finite numeric token syntax PPL-SPEC-000525

For supported numeric destinations and a checked policy providing any required scalar traits, input shall interpret finite tokens according to their exact rational values. A number part shall consist of an optional sign immediately followed by a nonempty mantissa, optionally followed by an exponent. A mantissa shall contain digits, optionally a single point with digits on at least one side. Unprefixed digits shall be decimal; leading zeros shall not select octal. 0x shall select radix 16, and a decimal radix followed by ^^ shall select any radix from 2 through 36. Letters shall denote digits 10 through 35 without case distinction; every mantissa digit shall be smaller than the selected radix.

For radix B, a mantissa with integer digit value M and k fractional digits shall denote MB − k before its sign and exponent. The exponent markers e and *^ shall multiply this value by BE; the hexadecimal-only marker p shall instead multiply by 2E. Exponent signs shall be optional and their digits shall always be decimal. A letter that is a valid mantissa digit shall take precedence over interpretation as an exponent marker; thus e shall be a digit at radix 15 or greater. The explicit marker *^ shall remain available in every radix. An explicit exponent magnitude shall not exceed LONG_MAX; excess magnitude shall be rejected without native overflow.

A slash immediately after a complete numerator part shall introduce a second signed part as denominator; the finite value shall be their exact ratio when that denominator is nonzero. Leading whitespace shall be accepted before either part, including after the slash, but not between a sign and its mantissa. A terminator outside the recognized part shall remain available to the stream after successful finite parsing. Type suffixes shall not be part of the numeric token. Resources and lexical arithmetic counters shall suffice for the requested token and exact value; no configured Coefficient width shall limit its mantissa. When exact expansion is needed after cancelling radix factors, the expansion budget shall be 2^26 bits plus twice the combined budget of the literal numerator and denominator mantissa digits. Each digit contributes the ceiling of the binary logarithm of its radix, including explicitly written zero digits. A conservative upper bound on the bits contributed by the remaining powers shall be checked separately on the numerator and denominator before materializing those powers. The budget applies to native destinations when magnitude classification needs exact expansion.

Radix powers contributed by the numerator and denominator and their common factors with the opposite mantissa shall be canceled before expanding the remaining powers. Native conversions may use proved magnitude bounds when the outcome is the same as conversion of the exact value.

2. Canonical rational input and stream failure outcomes PPL-SPEC-000526

The destination shall be live mpq_class storage, either raw or owned by Checked_Number<mpq_class, Policy>. The policy shall provide constant boolean has_nan and has_infinity traits for that wrapper's input and lifetime operations; no rounding default or result handler shall be required by named rational input. For an initially readable stream and a complete finite token in 🔗 1. Exact finite numeric token syntax, input shall assign its exact rational value in canonical form with positive denominator and coprime numerator/denominator. It shall return V_EQ for every valid rounding request, including strict and exactness requests. Lexical negative zero shall become rational zero. Reusing a destination shall not retain any previous numerator, denominator, sign or exponent component.

Successful parsing shall consume the recognized token and its leading whitespace, preserve any looked-ahead terminator by stream putback, and clear a speculative failbit caused only by successful end-of-token recognition at EOF. It shall retain eofbit and shall not clear a genuine stream failure. The stream buffer shall support the required character putback for successful delimiter retention. If that operation fails, input shall report failure through stream state rather than claim a complete finite value. Syntax rejection, an exponent expansion beyond the bound above or a conservative expansion bound exceeding the supported backend storage limits shall set failbit and return V_CVT_STR_UNK when the stream exception mask allows return. Enabled stream exceptions shall propagate. A consumed prefix shall not be rolled back after failure; no universal unchanged-destination promise shall apply. The surviving destination shall remain reassignable and destructible.

Case-insensitive inf with optional sign and unsigned nan shall be recognized as nonfinite tokens; a zero-valued denominator shall not be a successful finite value. Their nonfinite/undefined or unrepresentable outcome shall remain distinct from V_EQ finite input. This shall not promise a nonfinite representation in ordinary canonical mpq_class storage.

Objects and streams shall be synchronized against concurrent mutation and resources shall suffice for parsing and exact canonicalization. No library initialization owner, coefficient-constant stage, FPU setup/direction, inexact-flag support or irrational-precision setting shall be required.

3. Numeric text input into integral destinations PPL-SPEC-000527

For a successfully parsed finite token of exact value q in 🔗 1. Exact finite numeric token syntax, input into each native integer or Checked_Number<I, Check_Overflow_Policy<I>> type admitted in 🔗 3. Directed rational-to-integral conversion within range shall apply the canonical rational conversion rules in 🔗 3. Directed rational-to-integral conversion within range, 🔗 4. Truncated rational-to-integral conversion and lazy relation requests and 🔗 6. Rational conversion at and beyond integral endpoints, with the same destination value, range outcome, result relation and exactness precondition. Input into mpz_class shall use 🔗 2. Directed canonical rational conversion to an unbounded integer and 🔗 3. Delegated and exactness rational conversion to an unbounded integer. In particular, directed requests shall use floor/ceiling and delegated integer conversion shall truncate toward zero; ROUND_NOT_NEEDED shall require an integral finite token value representable in the selected destination.

Token precision shall not first be restricted to the configured coefficient range or to a native floating type. Named input shall return the numeric conversion result without automatically dispatching a policy error handler. The token shall remain consumed if subsequent numeric conversion reports an unrepresentable result. Stream behavior, source synchronization and resources shall follow 🔗 2. Canonical rational input and stream failure outcomes. Shared rational temporary pools shall be serialized in a build without thread-safe support; thread-safe builds shall use calling-thread pools. Destination and initialization prerequisites shall follow the corresponding conversion contracts, without requiring an FPU merely to parse or round a rational into integral storage.

4. Numeric text input into supported native floating destinations PPL-SPEC-000528

For a successfully parsed finite token of exact rational value q, input into raw or Checked_Number<F, Check_Overflow_Policy<F>> storage shall apply the value, direction, exactness and range rules in 🔗 1. Supported exact integer and rational conversion to native floating storage, 🔗 2. Directed conversion to adjacent finite normal floating-point bounds, 🔗 3. Directed conversion in the subnormal and underflow range, 🔗 4. Delegated and exactness requests for floating-point conversion and 🔗 5. Floating conversion overflow thresholds and computed-value classes for the corresponding configured supported native format. The returned relation shall compare q with the stored native value. Strict requests shall retain the precision of that rational conversion; native token parsing shall not round through a narrower intermediate format or the configured coefficient type.

A lexical negative-zero token shall parse as rational zero and therefore store positive native zero. Nonzero negative underflow shall retain the negative sign required by the rational conversion. Named input shall return its numeric outcome directly, without policy handler dispatch. Stream consumption/failure and temporary-pool prerequisites shall follow 🔗 3. Numeric text input into integral destinations. No library initialization owner, coefficient-constant stage or irrational-precision setting shall be needed, and hardware direction shall not change. Native format availability and any arithmetic conditions shall follow the cited rational conversion contracts.

5. Mathematical numeric output and stream delivery status PPL-SPEC-000529

output shall preserve a live source number and write its mathematical text using the supplied stream. With ordinary decimal formatting, native integer, mpz_class and canonical finite mpq_class sources shall use their exact ordinary integer/rational representation; character-sized integer sources shall be printed numerically rather than as glyphs. A native finite floating source shall be written as an exact finite decimal representation of its represented binary rational value, without rounding to the stream precision or changing hardware direction. Both zero signs shall be written as 0. Admitted native infinities and quiet NaNs shall be written as -inf, +inf and nan respectively.

Exact integer/rational output shall follow its ordinary stream formatting flags. Native floating mathematical output shall insert the exact decimal string instead of using the stream's native floating formatting. Pending width/fill/alignment shall act through the corresponding ordinary insertion; no newline shall be added. Live Numeric_Format instances shall select the same formatting rules. Every valid rounding request shall return V_EQ when insertion returns, indicating no numeric approximation; it shall not by itself certify successful stream delivery. Stream error state and enabled exceptions shall follow ordinary insertion semantics, without a partial-output rollback promise or policy handler dispatch by named output.

Resources shall suffice for exact decimal expansion and insertion; source, format and stream access shall be synchronized against mutation. Supported native formats shall satisfy their availability conditions. No library initialization owner, coefficient-constant stage, FPU rounding setup, inexact-flag support or irrational-precision setting shall be required. Ordinary decimal output read by compatible numeric input shall preserve the mathematical finite value, without promising to preserve a floating zero's sign or machine object representation.

6. Checked numeric stream policy integration PPL-SPEC-000530

For a Checked_Number<T, Policy> instantiation whose policy provides ROUND_DEFAULT_INPUT and handle_result(Result), input stream extraction shall call numeric input with that default direction and return the same stream reference. On a returned V_CVT_STR_UNK, it shall set failbit and shall not dispatch that syntax result to the policy handler. For another returned numeric result, it shall invoke the handler once. Stream exceptions and exceptions raised by the handler shall propagate. No successful destination value shall be inferred after a failed parse or a handler rejection; reuse shall meet the destination's declared post-failure prerequisites.

Output stream insertion shall require the policy handler, without requiring an input-default direction. It shall call numeric output with a default Numeric_Format and ROUND_IGNORE, dispatch a returned result to the policy handler once, and return the same output-stream reference. A stream exception shall propagate before a returned numeric result can be dispatched. The source shall remain unchanged by library formatting. Input/output mathematical values and stream semantics shall follow 🔗 2. Canonical rational input and stream failure outcomes, 🔗 3. Numeric text input into integral destinations, 🔗 4. Numeric text input into supported native floating destinations and 🔗 5. Mathematical numeric output and stream delivery status for admitted underlying types. Check_Overflow_Policy alone shall not be assumed to provide these stream-operator policy members; the named result-returning interfaces shall remain governed by their own contracts.