C++ checked scalar numerical limits
C_Integer_Type<I> shall have the truth value of C_Integer<I>::value. The default family shall contain the eleven native integer types below, excluding bool, wide character types and cv-qualified or reference types. GMP and native floating types shall not belong to this integer family.
For each of the eleven standard native integer types I and an admitted policy Policy, std::numeric_limits<Checked_Number<I, Policy>> shall describe the underlying integer format and its policy-reserved values. is_specialized, is_signed, is_integer, is_exact, is_bounded, radix, digits, digits10, max_digits10 and the four exponent fields shall equal their std::numeric_limits<I> counterparts. has_signaling_NaN shall equal the native field and shall be false for these integer types. These format fields shall describe storage; they shall not enlarge the finite interval after reserving special representations. has_infinity and has_quiet_NaN shall equal the policy's has_infinity and has_nan traits.
Let L and U be the native minimum and maximum. Let h be one when infinity is enabled and zero otherwise, and n be one when NaN is enabled and zero otherwise. For signed storage, the finite interval shall be [L + h + n, U − h]. For unsigned storage it shall be [0, U − 2h − n]. min() and lowest() shall return the lower finite endpoint; max() shall return the upper finite endpoint. The endpoint arithmetic here shall have its mathematical integer meaning. epsilon(), round_error() and denorm_min() shall return checked zero objects as placeholders for inapplicable floating-format quantities. signaling_NaN() shall have no admitted signaling-NaN result when has_signaling_NaN is false.
Each of these six finite factories shall return the checked scalar type, without requiring an implicit scalar conversion, a rounding default or a result handler. When infinity is enabled, infinity() shall return a checked positive infinity. When NaN is enabled, quiet_NaN() shall return a checked NaN. Those special factories shall likewise return the checked type and invoke no policy handler. Calls to a disabled special factory shall be outside this guarantee. Policy traits shall be coherent with the selected integer backend. These limits queries and factories shall require no library initialization or FPU setup and preserve hardware direction. Returned objects shall own their storage independently.
Generic numerical code needs the finite endpoints that remain after policy reservations. A factory for a checked type shall produce that type, so its use shall not depend on unrelated conversion defaults or handlers.
Public header: <ppl.hh>; effective instantiation:
template <typename I> concept C_Integer_Type = bool(C_Integer<I>::value); using N = Parma_Polyhedra_Library::Checked_Number<I, Policy>; using Limits = std::numeric_limits<N>; static N min(); static N max(); static N lowest(); static N epsilon(); static N round_error(); static N denorm_min(); static N infinity(); static N quiet_NaN();
The named format and capability fields shall be constant members of Limits. The special factories shall have the enabling conditions above.
Check format traits and factory result types for every standard native integer type. Exercise all four infinity/NaN trait combinations, deriving finite endpoints with independent unbounded integer arithmetic, and check min(), max() and lowest() against them; check the three zero placeholders and their result types. Confirm signaling NaN is not advertised. Classify every enabled special factory through PPL predicates. Use policies with no rounding defaults and a rejecting handler to establish handler independence. Check owned copies, preserved hardware direction, signedness alternatives for char, and every coefficient profile without library initialization.
src/C_Integer.hh; tests/commonhelpersspec1.cc; tests/numericpublic1.cc; src/checked_numeric_limits.hh; src/checked_int_inlines.hh; tests/numericlimitsspec1.cc.
For a configured supported native floating type F and an admitted policy, std::numeric_limits<Checked_Number<F, Policy>> shall expose the underlying floating format's is_specialized, is_signed, is_integer, is_exact, is_bounded, radix, digits, digits10, max_digits10, four exponent fields, has_denorm and has_denorm_loss. Each shall equal its native F counterpart. For policies admitting the format's infinity and NaN, has_infinity, has_quiet_NaN and has_signaling_NaN shall equal their native fields.
min(), max(), lowest(), epsilon(), round_error() and denorm_min() shall return checked objects containing exactly the corresponding native factory values, with their signs preserved. In particular, min() shall denote the smallest positive normal value, lowest() the most negative finite value and max() the largest finite value. If the format and policy admit infinity or quiet NaN, infinity() or quiet_NaN() respectively shall return a checked object of that class. If has_signaling_NaN is true and the policy admits NaN, signaling_NaN() shall return a checked signaling NaN of the native format. A false signaling capability shall admit no such result. Signaling NaN shall retain the native format's invalid-operation signaling behavior on arithmetic use; this shall not invoke a PPL policy handler merely by obtaining its representation. No NaN payload or NaN sign shall be prescribed.
Each named factory shall return the checked type, independently of implicit conversion permission, rounding defaults and policy handlers. No handler shall be invoked. The underlying floating type shall have its configured format enabled; the policy shall admit each requested special value. Calls shall require no library initialization or FPU rounding setup, preserve hardware direction and produce independently owned storage.
Checked floating storage retains its native representation and format constants. Returning checked objects makes those constants usable even with policies that intentionally provide no value-conversion defaults.
Public header: <ppl.hh>; effective instantiation for configured F:
using N = Parma_Polyhedra_Library::Checked_Number<F, Policy>; using Limits = std::numeric_limits<N>; static N min(); static N max(); static N lowest(); static N epsilon(); static N round_error(); static N denorm_min(); static N infinity(); static N quiet_NaN(); static N signaling_NaN();
The named format fields shall be constant members of Limits.
For each configured native floating format, check every named trait and the result type of each factory. Compare finite factory values and signs with native format constants, including subnormal minima, and classify enabled infinity and quiet NaN without prescribing a NaN payload. Where signaling NaN is advertised, verify its factory result type and native signaling behavior under a saved nontrapping floating environment; restore that environment afterward. Exercise transparent, overflow-checking and extended policies, including policies without rounding defaults, and verify handler independence, object copying and preserved hardware direction under all four hardware modes.
src/checked_numeric_limits.hh; tests/numericlimitsspec1.cc.
For T equal to mpz_class or mpq_class, std::numeric_limits<Checked_Number<T, Policy>> shall report is_specialized, is_signed and is_exact as true, is_bounded as false and radix as two. is_integer shall be true for unbounded integers and false for rationals. digits, digits10, max_digits10 and all four exponent fields shall be zero; those zeros shall indicate that no finite format limit is supplied. has_infinity and has_quiet_NaN shall equal the policy's has_infinity and has_nan traits. has_signaling_NaN shall be false; signaling_NaN() shall have no admitted signaling-NaN result.
min(), max(), lowest(), epsilon(), round_error() and denorm_min() shall return checked zero objects as placeholders for inapplicable bounded-format quantities. These zeros shall not denote finite range bounds or nonzero spacing between rational values. Each named factory shall return the checked type, without requiring an implicit conversion, rounding default or policy handler. No handler shall be invoked.
When the policy enables infinity, infinity() shall return checked positive infinity; when it enables NaN, quiet_NaN() shall return checked NaN. These factories shall return checked objects and invoke no handler. Disabled special factories shall be outside this guarantee. Extended GMP storage shall be interpreted through PPL's special-value queries rather than ordinary GMP arithmetic on nonfinite representations.
The policy shall provide the backend's relevant representation traits. Available resources shall suffice for object construction and ownership. These metadata queries and factories shall require no library initialization, coefficient constants or FPU rounding setup, and preserve hardware direction. Returned values and their copies shall own independent storage.
Unbounded exact scalars have no finite extrema or fixed precision. Explicit metadata and placeholder meanings prevent generic callers from mistaking zero for a range boundary, while retaining checked extended-value factories.
Public header: <ppl.hh>; effective instantiation for either GMP scalar:
using N = Parma_Polyhedra_Library::Checked_Number<T, Policy>; using Limits = std::numeric_limits<N>; static N min(); static N max(); static N lowest(); static N epsilon(); static N round_error(); static N denorm_min(); static N infinity(); static N quiet_NaN();
The named format and capability fields shall be constant members of Limits. The special factories shall have the enabling conditions above.
Check unbounded integer and rational metadata for all four infinity/NaN policy combinations. Confirm signaling NaN is not advertised. Check the result types and zero values of the six finite placeholders. Classify enabled extended factories through PPL, without ordinary GMP arithmetic on their nonfinite storage. Verify independent ownership by copying and modifying finite results, handler independence with a rejecting handler and no rounding defaults, preserved hardware direction and meaningful execution when native floating kernels are disabled.
src/checked_numeric_limits.hh; src/mp_std_bits_defs.hh; tests/numericlimitsspec1.cc.