C++ native scalar conversion to native floating-point storage
|
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:
4. Rounding, result classes and state for finite native binary arithmetic
2. Delegated and exactness native integral conversion to native floating point
2. Delegated and exactness native integral conversion to native floating point
2. Delegated and exactness native integral conversion to native floating point
2. Delegated and exactness native integral conversion to native floating point
3. Exact native floating-point assignment to the same or a wider native format
4. Directed narrowing between finite native floating-point formats
6. Range limits in conversion of finite native scalars to floating point
2. Mixed finite floating and exact scalar ordering
9 |
The destination shall be a configured supported native floating-point type F in 🔗 1. Supported exact integer and rational conversion to native floating storage, or Checked_Number<F, Check_Overflow_Policy<F>>. The source shall be one of the eleven native integral types in 🔗 1. Exact conversion between native and checked integral scalars, or its Checked_Number<I, Check_Overflow_Policy<I>> wrapper, with integer value a. It shall be independent of the configured Coefficient alias. Within the destination finite range, ROUND_DOWN shall assign the greatest representable value no greater than a; ROUND_UP shall assign the least representable value no less than a. Exactly representable integers shall preserve their values. Source-range crossings shall follow 🔗 6. Range limits in conversion of finite native scalars to floating point. Zero shall produce positive zero. Let p be std::numeric_limits<F>::digits and w the native source type's object width CHAR_BIT * sizeof(I). When p > w, conversion shall return V_EQ under every directed/strict request and shall require no particular hardware rounding direction. Otherwise, downward conversion shall return V_GE and upward conversion V_LE without the strict flag. With that flag and available definite native inexact information, an exact result shall return V_EQ and an inexact result V_GT downward or V_LT upward. If definite inexact information is unavailable, the corresponding weak relation shall be returned. These potentially inexact directed conversions shall require upward hardware rounding and shall preserve that direction. The destination shall be live and assignable, and a distinct source shall remain unchanged. Callers shall synchronize access against concurrent object mutation. Floating-point exceptions shall be nontrapping; accrued flags shall be unspecified. Native conversions using FPU control or inexact queries shall require an available backend. On IA-32 backends using SSE, runtime SSE detection shall have completed before those facilities are used, through 🔗 1. Initialization owners and automatic C++ initialization and 🔗 3. Thread initialization, default state and finalization or fpu_initialize_control_functions(). C99-fenv and SPARC backends shall require no library or thread initialization object. No coefficient-constant stage or shared numerical temporary pool shall be required. The _r interface shall return the conversion result without policy-handler dispatch. |
Native integer embedding can remain exact or provide adjacent directed bounds without introducing an intermediate bounded coefficient. Result precision and native floating-point state prerequisites are part of that conversion interface. |
|
|
|
|
|
Cross every configured destination format with all eleven native integral types and their checked wrappers. Check full endpoints, zero, signed values and precision-boundary integers against independent unbounded-integer/dyadic oracles. Require adjacent directed bounds, exact or weak/strict classifications as specified, positive zero, preserved sources and hardware direction; use every hardware mode for uniform exact embeddings. |
src/checked_float_inlines.hh; src/Checked_Number_defs.hh and src/Checked_Number_inlines.hh; tests/nativefloatingconversionspec1.cc. tests/smallconstantassign1.cc. |
|
|
Public header: <ppl.hh>; effective template instantiation for admitted integral From and floating To types: Result assign_r(To& to, const From& from, Rounding_Dir dir); |
||
|
SW_SPEC
|
2 |
|
|
|
For the integral source/destination types in 🔗 1. Directed native integral conversion to native floating-point storage, ROUND_IGNORE shall use the current hardware rounding direction to convert a. Within finite range it shall use the nearest allowed destination value in that direction; nearest-even hardware mode shall resolve exact midpoints toward an even significand. Range behavior shall follow 🔗 6. Range limits in conversion of finite native scalars to floating point. ROUND_NOT_NEEDED shall require the source integer to be exactly representable as a finite destination value and shall assign that value. When p > w as defined in 🔗 1. Directed native integral conversion to native floating-point storage, all these requests shall return V_EQ. Otherwise, an unflagged delegated request shall return V_LGE. A strict delegated request with definite native inexact information shall return V_EQ for an exact result and V_NE for an inexact result; if that information is unavailable it shall return V_LGE. An unflagged no-rounding-needed request shall return V_EQ in an assertion-enabled build and may return lazy V_LGE in a build defining NDEBUG. A strict no-rounding-needed request shall retain its exact-representability precondition and return V_EQ. Unflagged delegated and no-rounding-needed requests shall require no particular current hardware direction and shall preserve it. A strict delegated request that uses inexact queries shall require upward hardware direction and preserve it. Source/destination validity, synchronization, backend setup, initialization independence, exception conditions and result-returning behavior shall follow 🔗 1. Directed native integral conversion to native floating-point storage. |
Delegation preserves the caller-selected native rounding behavior, while a no- rounding-needed request carries an exact-representability precondition. A strict inexact result can be known to differ without specifying which side was chosen by a delegated mode. |
|
|
|
|
|
Check delegated conversions under every hardware mode with independent exact integer and adjacent-native-value distance oracles, including nearest-even midpoints. Check exactness requests only for exactly representable finite inputs in both build modes. Test uniform exact source types separately from potentially inexact source types, strict exact/inexact statuses, unavailable- inexact-information fallbacks, source preservation and hardware direction. |
src/checked_float_inlines.hh; src/Checked_Number_defs.hh and src/Checked_Number_inlines.hh; tests/nativefloatingconversionspec1.cc. tests/smallconstantassign1.cc. |
|
|
Public header: <ppl.hh>; effective template instantiation for the integral-source conversions in 🔗 1. Directed native integral conversion to native floating-point storage: Result assign_r(To& to, const From& from, Rounding_Dir dir); |
||
|
SW_SPEC
|
3 |
|
|
Incoming link from:
4. Directed narrowing between finite native floating-point formats
1 |
The source and destination shall be raw or Checked_Number<T, Check_Overflow_Policy<T>> instances of configured supported native floating-point types. The source shall be finite. When sizeof(From_native) <= sizeof(To_native) and the configured destination format contains every finite source value exactly, assign_r shall preserve the represented value and return V_EQ for every base direction, with or without ROUND_STRICT_RELATION. Either signed zero shall retain its sign. This shall include same-format assignments and native double/long double formats having equal precision and storage size. Source and destination may be the same object or share storage through a checked object's raw-value reference when their native types agree. The conversion shall use the source entry value. A source with distinct storage shall remain unchanged, and later destination mutation shall not affect it. No particular hardware rounding direction, native inexact query, library or thread initialization object, coefficient-constant stage or shared numerical temporary pool shall be required. Calls shall preserve hardware direction. Destination validity, object synchronization, availability, exception conditions and result-returning behavior shall follow 🔗 1. Directed native integral conversion to native floating-point storage. |
An exact embedding between native formats is independent of a global coefficient width and does not require the FPU to establish an approximation direction. |
|
|
|
|
|
Cross every configured source/destination format pair admitting the exact route, with raw and checked sources/destinations. Compare exact dyadic values and zero signs at subnormals, normal boundaries, precision limits and finite source maxima. Check all direction/strict requests, every hardware mode, self/raw-storage aliases and independent copies without initialization stages. |
src/checked_float_inlines.hh; src/Checked_Number_defs.hh and src/Checked_Number_inlines.hh; tests/nativefloatingconversionspec1.cc. |
|
|
Public header: <ppl.hh>; effective template instantiation for admitted floating-point To and From types: Result assign_r(To& to, const From& from, Rounding_Dir dir); |
||
|
SW_SPEC
|
4 |
|
|
|
For configured native source/destination formats and raw or checked types in 🔗 3. Exact native floating-point assignment to the same or a wider native format with sizeof(From_native) > sizeof(To_native), the source shall be finite with exact represented value a. When a lies within destination finite range, ROUND_DOWN shall assign the greatest representable value no greater than a; ROUND_UP shall assign the least representable value no less than a. This shall include transitions between normal, subnormal and signed-zero values. A zero result shall retain the source's sign. Source-range crossings shall follow 🔗 6. Range limits in conversion of finite native scalars to floating point. Without ROUND_STRICT_RELATION, downward conversion shall return V_GE and upward conversion V_LE, even for an exactly representable source. With the flag and definite native inexact information, it shall return V_EQ for exactness, V_GT for an inexact downward result and V_LT for an inexact upward result. When definite inexact information is unavailable, it shall return the corresponding weak relation. These directed conversions shall require upward hardware rounding and shall preserve that direction. The source shall remain unchanged and the destination shall be live and assignable. Object synchronization, backend setup, availability, initialization independence, exception conditions and result-returning behavior shall follow 🔗 1. Directed native integral conversion to native floating-point storage. |
Native narrowing must preserve the selected bound even across underflow into subnormal or zero values. A weak relation remains meaningful when a backend cannot resolve native inexactness. |
|
|
|
|
|
For every actual narrowing pair and raw/checked combination, use exact significand rational oracles at midpoint neighborhoods, precision limits, normal/subnormal transitions and tiny nonzero inputs. Check tight bounds, signed zeros, exact/weak/strict classifications, source preservation and unchanged upward hardware direction. Exercise definite and unavailable native inexact classifications. |
src/checked_float_inlines.hh; src/Checked_Number_defs.hh and src/Checked_Number_inlines.hh; tests/nativefloatingconversionspec1.cc. |
|
|
Public header: <ppl.hh>; effective template instantiation for admitted floating-point To and From types: Result assign_r(To& to, const From& from, Rounding_Dir dir); |
||
|
SW_SPEC
|
5 |
|
|
|
For the narrowing source/destination types in 🔗 4. Directed narrowing between finite native floating-point formats, ROUND_IGNORE shall convert the source's finite represented value using the current hardware direction. The nearest-even mode shall resolve exact midpoints toward an even significand. A zero result shall retain the source's sign. Source-range crossings shall follow 🔗 6. Range limits in conversion of finite native scalars to floating point. ROUND_NOT_NEEDED shall require a source value exactly representable as a finite destination value and shall preserve that value and zero sign. An unflagged delegated request shall return V_LGE. With the strict flag and definite native inexact information, it shall return V_EQ for an exact result and V_NE for an inexact result; unavailable inexact information shall give V_LGE. An unflagged no-rounding-needed request shall return V_EQ in an assertion-enabled build and may return lazy V_LGE in a build defining NDEBUG. A strict no-rounding-needed request shall retain its exact-representability precondition and return V_EQ. Unflagged delegated and no-rounding-needed requests shall admit every current hardware direction and preserve it. A strict delegated request using native inexact queries shall require upward hardware direction and preserve it. Source/destination validity, source preservation, synchronization, backend setup, availability, initialization independence, exception conditions and result-returning behavior shall follow 🔗 4. Directed narrowing between finite native floating-point formats. |
Native delegation and an asserted exact conversion have different preconditions and classifications. Their value guarantees do not disappear when lazy status information is returned. |
|
|
|
|
|
Check delegated rounding in every hardware direction using exact dyadic distance and nearest-even midpoint oracles, for all actual narrowing pairs and raw/checked combinations. Check valid no-rounding-needed sources in both build modes, strict exact/inexact statuses, zero signs, source preservation and direction. Keep exactly representable and inexact source sets distinct. |
src/checked_float_inlines.hh; src/Checked_Number_defs.hh and src/Checked_Number_inlines.hh; tests/nativefloatingconversionspec1.cc. |
|
|
Public header: <ppl.hh>; effective template instantiation for admitted floating-point To and From types: Result assign_r(To& to, const From& from, Rounding_Dir dir); |
||
|
SW_SPEC
|
6 |
|
|
Incoming links from:
4. Rounding, result classes and state for finite native binary arithmetic
1. Directed native integral conversion to native floating-point storage
2. Delegated and exactness native integral conversion to native floating point
4. Directed narrowing between finite native floating-point formats
5. Delegated and exactness native floating-point narrowing
5 |
For the native scalar conversions in 🔗 1. Directed native integral conversion to native floating-point storage and 🔗 4. Directed narrowing between finite native floating-point formats, let M be the destination's maximum finite value and let a be a finite source outside [ − M, M]. For a > M, downward conversion shall assign M and upward conversion positive infinity. For a < − M, upward conversion shall assign − M and downward conversion negative infinity. Delegated conversion shall use the current hardware direction. Toward-zero mode shall choose the finite endpoint; directed modes shall choose the corresponding endpoint or infinity above. In nearest-even mode, let u = 2emax − p be the last finite binade's spacing, where std::numeric_limits<F>::max_exponent is emax and destination precision is p. A magnitude below M + u ⁄ 2 shall choose the finite endpoint; a magnitude at or above that threshold shall choose the corresponding infinity. Every finite computed endpoint shall have class VC_NORMAL and shall use the weak/strict relation of its conversion request. Every computed positive infinity shall have class VC_PLUS_INFINITY and every computed negative infinity VC_MINUS_INFINITY, with the corresponding conversion relation. These native infinities shall be representable, without V_UNREPRESENTABLE. The conversion shall not promise an integer-overflow annotation for a finite directed endpoint. No-rounding-needed requests shall retain their finite exact-representability precondition and shall not admit these source values. Object, state, availability and backend prerequisites shall follow the applicable conversion above. |
A directed finite endpoint and an infinite bound can both be valid approximations. The result class must nevertheless describe the value actually stored, independently of how precisely its relation is reported. |
|
|
|
|
|
Use both signs of source values immediately beyond the destination maximum, the nearest-overflow midpoint and much larger finite values for every narrowing format pair. Check directed and delegated values, exact class fields, weak/strict relations and representability; repeat for native integral sources whenever their available width reaches this range. Preserve sources and hardware direction, with no invalid native casts or no-rounding-needed requests. |
src/checked_float_inlines.hh; src/Checked_Number_defs.hh and src/Checked_Number_inlines.hh; tests/nativefloatingconversionspec1.cc. |
|
|
Public header: <ppl.hh>; effective template instantiation for admitted floating-point To and From types: Result assign_r(To& to, const From& from, Rounding_Dir dir); |