C++ numerical policies and operation capabilities
|
Type
|
Level
|
MID
|
UID
|
REFS
|
Title
|
Statement
|
Rationale
|
Comment
|
BIBLIOGRAPHY
|
STATUS
|
COMPONENT
|
APPLICABILITY
|
VERIFICATION_METHODS
|
VERIFICATION_CRITERIA
|
SOURCE
|
LANGUAGE
|
VISIBILITY
|
INTERFACE
|
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
SW_SPEC
|
1 |
|
|
Incoming links from:
1. Conversion of policy-admitted scalar special values
1. Conversion of policy-admitted scalar special values
2. Unary and binary-scale transformations of scalar special values
3. Extended scalar binary arithmetic and enabled fault diagnosis
4. Nonfinite remainder operands and enabled modulus faults
5. Extended accumulated products and enabled fault diagnosis
6. Square-root special values and enabled negative-input diagnosis
2. Finite checked scalar converting construction and assignment
3. Checked scalar storage references and value conversion
3. Result-returning overflow-checking policy
10 |
Checked_Number<T, Policy> shall obtain numerical checks, special-value capabilities, rounding defaults and result handling from the members of Policy required by the selected operation. Availability of one operation shall not require policy members used only by another operation. Checking and capability flags required by a selected operation shall be constant expressions. Default construction, same-type copying and raw storage access shall not require a rounding default or handle_result. A named result-returning operation with an explicit Rounding_Dir shall return its Result without invoking a policy handler; its scalar backend's relevant checking and special-value traits shall still be required. Named rational input shall admit the two-trait policy specified by 🔗 2. Canonical rational input and stream failure outcomes. A value-converting constructor with an explicit direction shall invoke the destination policy's handle_result for the conversion result without requiring a rounding default. The corresponding constructor without a direction shall use ROUND_DEFAULT_CONSTRUCTOR and that handler. Overloaded arithmetic operators shall use ROUND_DEFAULT_OPERATOR; named assignment functions that omit a direction, such as div_2exp_assign, shall use ROUND_DEFAULT_FUNCTION. Each shall pass the numerical result to handle_result after its numerical operation. Handler exceptions shall propagate. Same-type copy assignment shall copy storage without invoking a conversion handler. Checked stream operators shall have the capability and dispatch rules of 🔗 6. Checked numeric stream policy integration: input uses ROUND_DEFAULT_INPUT and a handler; output uses ROUND_IGNORE and a handler. Neither shall require ROUND_DEFAULT_OUTPUT. Availability of the underlying implicit conversion to T shall require a policy that provides true convertible. Operation-specific numerical, aliasing, resource and synchronization preconditions shall continue to apply. Policy constants and direct policy handlers shall require no library initialization or FPU rounding setup. |
Result-returning calls permit callers to inspect outcomes directly. Rounding defaults and automatic result handling are additional capabilities needed by specific convenience interfaces, rather than prerequisites for all checked storage. |
|
|
|
|
|
Instantiate checked storage and named result-returning calls with policies having no rounding defaults or handler. Exercise a handler-only policy with an explicit-direction constructor. Use distinct constructor, operator and function defaults with a recording handler to check directed fractional results and exactly one handler call. Confirm raw access, same-type copying and named result-returning calls do not invoke the handler, and that handler exceptions propagate. Inspect template dependencies and conversion-member requirements without calling an unsupported interface. |
src/Checked_Number_defs.hh; src/Checked_Number_inlines.hh; tests/numericpoliciesspec1.cc; tests/numericpublic1.cc. |
|
|
Public header: <ppl.hh>; effective template instantiations in PPL: template <typename T, typename Policy> class Checked_Number; Checked_Number(); Checked_Number(const Checked_Number& source); Checked_Number(int source, Rounding_Dir dir); Checked_Number(int source); Checked_Number(const mpq_class& source, Rounding_Dir dir); Checked_Number(const mpq_class& source); Checked_Number& operator=(const Checked_Number& source); T& raw_value(); const T& raw_value() const; operator T() const; The value-converting constructors above shall represent the admitted integer and rational source forms. Named numerical operations, arithmetic operators and stream operators shall retain their separate interface contracts; a policy shall provide the members those operations require. |
||
|
SW_SPEC
|
2 |
|
|
Incoming link from:
5. Bounded integer coefficient policy configuration
1 |
For supported scalar T, Checked_Number_Transparent_Policy<T> shall provide the following constant boolean traits:
Its ROUND_DEFAULT_CONSTRUCTOR, ROUND_DEFAULT_OPERATOR, ROUND_DEFAULT_FUNCTION, ROUND_DEFAULT_INPUT and ROUND_DEFAULT_OUTPUT shall each equal ROUND_NATIVE. handle_result(r) shall return without throwing or changing observable state for every admitted Result code, including diagnostics and unrepresentability flags. It shall not convert a diagnostic into a successful numerical outcome. Numerical operations shall retain their own valid-input, representability and rounding preconditions; disabled checks shall not promise defined native arithmetic outside those preconditions. |
A transparent policy supplies ordinary native defaults while leaving numerical failures to the caller and the underlying operation's contract. |
|
|
|
|
|
Check every named trait and rounding default for all native integer types, supported native floating formats, mpz_class and mpq_class. Pass all named result codes, with and without the unrepresentability flag, to the handler and confirm normal return and preserved rounding state. Exercise valid finite checked construction, arithmetic, named functions, conversion and streams using this policy without library initialization. |
src/checked_defs.hh; src/Checked_Number_inlines.hh; tests/numericpoliciesspec1.cc. |
|
|
Public header: <ppl.hh>; policy in PPL: template <typename T> struct Checked_Number_Transparent_Policy; static void handle_result(Result result); The named traits and rounding defaults shall be constant policy members. |
||
|
SW_SPEC
|
3 |
|
|
Incoming link from:
4. Extended numerical policy and NaN-class handler
1 |
For supported scalar T, Check_Overflow_Policy<T> shall provide true check_overflow, convertible, check_fpu_inexact and check_fpu_nan_result. Its check_inf_add_inf, check_inf_sub_inf, check_inf_mul_zero, check_div_zero, check_inf_div_inf, check_inf_mod and check_sqrt_neg shall be false. has_nan shall equal std::numeric_limits<T>::has_quiet_NaN and has_infinity shall equal std::numeric_limits<T>::has_infinity. The policy shall provide no ROUND_DEFAULT_CONSTRUCTOR, ROUND_DEFAULT_OPERATOR, ROUND_DEFAULT_FUNCTION, ROUND_DEFAULT_INPUT, ROUND_DEFAULT_OUTPUT or handle_result. Checked storage using this policy shall support default construction, raw access and applicable explicit-direction result-returning calls under 🔗 1. Operation-specific numerical policy capabilities. Those calls shall expose overflow and other outcomes through Result according to their individual contracts. Automatic handler dispatch shall require a policy that additionally provides a handler; convenience interfaces using defaults shall additionally require those defaults. Enabling overflow checks shall not enable the seven separate invalid-operation checks listed above. |
A caller that inspects numerical result codes needs checking capabilities without an imposed exception policy or implicit rounding choice. |
|
|
|
|
|
Check the trait values and absence of all defaults and the handler for each supported scalar family. Compile and run default-constructed checked storage with explicit-direction named operations, including representable values and bounded range overflow. Compare result classes and overflow flags with the corresponding conversion contracts without invoking an unavailable generic constructor, arithmetic operator or stream interface. |
src/Checked_Number_defs.hh; tests/numericpoliciesspec1.cc. |
|
|
Public header: <ppl.hh>; policy in PPL: template <typename T> struct Check_Overflow_Policy; The named boolean traits shall be constant policy members. |
||
|
SW_SPEC
|
4 |
|
|
|
Extended_Number_Policy shall provide true check_overflow, has_nan, has_infinity, check_fpu_inexact and check_fpu_nan_result. Its check_inf_add_inf, check_inf_sub_inf, check_inf_mul_zero, check_div_zero, check_inf_div_inf, check_inf_mod and check_sqrt_neg shall be false. It shall provide no convertible member and none of the five rounding defaults listed in 🔗 3. Result-returning overflow-checking policy. In particular, supplying this policy shall not enable an implicit conversion to the underlying scalar type. For admitted Result codes, handle_result(r) shall invoke throw_result_exception(r) exactly when result_class(r) == VC_NAN, with the exception categories specified by 🔗 8. Exception classification of numerical result codes. For every other class it shall return without throwing, including infinity, bounded-overflow and unrepresentability flags. Those other outcomes shall retain their original numerical meanings; normal return from this handler shall not imply successful exact arithmetic or representability. The special-value capability traits shall enable supported extended representations in the selected scalar backend; they shall not promise that every native storage type can physically encode all such representations. The disabled invalid-operation checks shall retain the underlying operation's preconditions. |
Extended storage capability and automatic exception handling are distinct. The handler rejects NaN-class results while allowing callers to use extended infinities under their numerical contracts. |
|
|
|
|
|
Check every trait, absence of conversion permission and absence of rounding defaults. Use a literal expected class/exception table for named result codes, both with and without unrepresentability. Confirm that only NaN-class codes reach the exception mapper and that other classes return unchanged, including bounded-overflow results. Exercise explicit-direction checked construction with this handler and finite valid operands. |
src/Checked_Number_defs.hh; src/Checked_Number_inlines.hh; tests/numericpoliciesspec1.cc. |
|
|
Public header: <ppl.hh>; policy in PPL: struct Extended_Number_Policy; static void handle_result(Result result); The named boolean traits shall be constant policy members. |
||
|
SW_SPEC
|
5 |
|
|
|
In bounded integer coefficient configurations, Bounded_Integer_Coefficient_Policy shall provide true check_overflow, convertible and check_fpu_nan_result. Its has_nan, has_infinity and check_fpu_inexact shall be false, as shall check_inf_add_inf, check_inf_sub_inf, check_inf_mul_zero, check_div_zero, check_inf_div_inf, check_inf_mod and check_sqrt_neg. Each of the five rounding defaults listed in 🔗 2. Transparent numerical policy shall equal ROUND_NATIVE. In checked bounded coefficient configurations, handle_result(r) shall invoke throw_result_exception(r) exactly when result_overflow(r) is true or result_class(r) == VC_NAN, with the categories of 🔗 8. Exception classification of numerical result codes. Otherwise it shall return without throwing. The overflow query shall have the code-sensitive meaning specified by 🔗 3. Overflow-sign and storage-representability result queries, including its treatment of annotated normal-class codes and class-based infinity signs. Checked coefficient operations shall retain the failure guarantees of 🔗 5. Checked coefficient overflow and result-policy dispatch. In unchecked native coefficient configurations, the policy's declaration shall not confer checked arithmetic behavior on the configured native Coefficient type or promise a linkable handler implementation. |
The configured coefficient profile determines the arithmetic and handler that are available. A policy declaration shared with native profiles shall not imply overflow protection for those native coefficients. |
|
|
|
|
|
Check all traits and five defaults in every checked and unchecked bounded profile. In checked profiles, pass ordinary relations, infinities, bounded overflow and NaN-class diagnostics to the handler, with and without the unrepresentability flag. Confirm the selected exception categories and ordinary return paths. Compile GMP configurations without referring to this bounded-only declaration, and do not call its handler in native profiles. |
src/Coefficient_types.hh; src/Coefficient_inlines.hh; tests/numericpoliciesspec1.cc. |
|
|
Public header: <ppl.hh>; policy in PPL for bounded configurations: struct Bounded_Integer_Coefficient_Policy; static void handle_result(Result result); The named boolean traits and rounding defaults shall be constant policy members. Direct handler calls shall be admitted only in checked bounded coefficient configurations. |