C++ native and rational square roots and irrational precision
|
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 link from:
6. Checked named nonnegative square root
1 |
The source and destination shall be configured native F or Checked_Number<F, Check_Overflow_Policy<F>> types with the same floating-point format, as in 🔗 4. Rounding, result classes and state for finite native binary arithmetic. The source shall be finite and nonnegative, including either signed zero, with represented value a. sqrt_assign_r shall compute the nonnegative real √(a). ROUND_DOWN shall assign its greatest representable lower bound and ROUND_UP its least representable upper bound. ROUND_IGNORE shall use the current hardware direction, including nearest-even midpoint selection. Exactly representable roots shall preserve their values. A zero root shall retain the source zero's sign. Every computed result for this source domain shall be finite and have class VC_NORMAL, without V_UNREPRESENTABLE. Weak, strict, delegated and no-rounding-needed result relations shall follow 🔗 4. Rounding, result classes and state for finite native binary arithmetic, with exactness relative to √(a). A no-rounding-needed request shall require that root to be exactly representable. Directed, strict and no-rounding-needed requests shall require upward hardware rounding; unflagged delegated requests shall admit every current hardware direction. Calls shall preserve the current direction. Source/destination aliases, source preservation, object validity, synchronization, native backend setup, initialization independence and floating-point exception conditions shall follow 🔗 4. Rounding, result classes and state for finite native binary arithmetic. |
A square-root bound can be checked exactly by squaring its nonnegative endpoints. Finite nonnegative native inputs need no artificial coefficient- range restriction. |
|
|
|
|
|
Compare squared result and adjacent-native-value bounds with exact rational source values for zero, perfect squares, nonsquares, precision boundaries, subnormals, normal minima and finite maxima. Check all admitted raw/checked forms, directed/delegated/strict statuses, nearest selection, valid exactness requests, signed zeros, self/raw aliases and hardware-state preservation. |
src/checked_float_inlines.hh; src/Checked_Number_defs.hh and src/Checked_Number_inlines.hh; tests/squarerootspec1.cc. |
|
|
Public header: <ppl.hh>; effective template instantiation for admitted same-format To and From types: Result sqrt_assign_r(To& to, const From& from, Rounding_Dir dir); |
||
|
SW_SPEC
|
2 |
|
|
Incoming links from:
2. Euclidean distance of bounded-difference closed-bound tables
2. Euclidean distance between Box endpoint tuples
6. Checked named nonnegative square root
18. Euclidean distance between bound-entry arrays
2. Euclidean distance between generator points
3. Euclidean distance of octagonal closed-bound tables
7. Euclidean distance of physical octagonal entry arrays
3. Selection and ownership of irrational rational precision
8 |
The source and destination shall be mpq_class. The source shall be finite, canonical and nonnegative, with value a; canonical form shall follow 🔗 1. Exact rational assignment from rational and integral sources. Let p be the current precision in 🔗 3. Selection and ownership of irrational rational precision and S = 2p. Zero shall produce canonical zero and V_EQ for every supported direction/strict flag. For a > 1, the downward result shall be ⌊S√(a)⌋ ⁄ S and the upward result ⌈S√(a)⌉ ⁄ S. For 0 < a ≤ 1, the downward result shall be S ⁄ ⌈S ⁄ √(a)⌉ and the upward result S ⁄ ⌊S ⁄ √(a)⌋. Results shall be canonical, nonnegative rationals with the lesser of numerator and denominator no greater than S. Without the strict flag the downward relation shall be V_GE and the upward relation V_LE. With the flag, exactness shall give V_EQ, a strict lower bound V_GT and a strict upper bound V_LT. ROUND_IGNORE shall produce one of these two precision-grid bounds and return a relation containing the actual comparison of √(a) with the result. With a strict flag it shall determine V_EQ, V_GT or V_LT. ROUND_NOT_NEEDED shall require an exact root on the selected grid: S√(a) shall be an integer for a > 1, or S ⁄ √(a) an integer for 0 < a ≤ 1. It shall return that exact root, with V_EQ in an assertion-enabled build and permitted lazy V_LGE in a build defining NDEBUG; a strict exactness request shall return V_EQ. Source and destination may be the same object. Source numerator/denominator references borrowed by the caller shall not be used across a modifying call. A source with distinct storage shall remain unchanged. The destination shall be live and assignable. Resource availability shall limit unbounded intermediates. No FPU direction, library/thread initialization object or coefficient-constant stage shall be required. Hardware direction shall remain unchanged. The precision shall remain stable throughout the call. Non-thread-safe configurations shall serialize shared precision and lazy temporary-pool use; thread-safe configurations shall use the calling thread's precision and pools. Object access shall be synchronized against concurrent mutation. The _r interface shall return its result without policy-handler dispatch. |
A selected rational precision defines a finite grid for square-root approximation while preserving sound directed bounds both above and below one. The result relation must describe the final root approximation rather than an intermediate integer division. |
|
|
|
|
|
Use independent integer/rational squared comparisons and grid-index searches for zero, one, perfect/nonperfect rational squares and values above/below one, at precision0 and increasing finite precisions. Check canonical bounds, numerator/denominator limits, weak/strict/delegated relations, valid selected- grid exactness requests, source/self-alias preservation, precision stability and FPU independence in every coefficient profile. |
src/checked_mpq_inlines.hh; src/checked_mpz_inlines.hh; src/checked.cc; src/Checked_Number_defs.hh and src/Checked_Number_inlines.hh; tests/squarerootspec1.cc. |
|
|
Public header: <ppl.hh>; effective template instantiation: Result sqrt_assign_r(mpq_class& to, const mpq_class& from, Rounding_Dir dir); |
||
|
SW_SPEC
|
3 |
|
|
Incoming links from:
2. Euclidean distance of bounded-difference closed-bound tables
2. Euclidean distance between Box endpoint tuples
6. Checked named nonnegative square root
18. Euclidean distance between bound-entry arrays
2. Euclidean distance between generator points
3. Euclidean distance of octagonal closed-bound tables
7. Euclidean distance of physical octagonal entry arrays
2. Finite rational square root at the selected irrational precision
8 |
irrational_precision() shall return the current unsigned precision parameter. set_irrational_precision(p) shall accept every value from zero through INT_MAX and make subsequent reads return p. For a value greater than INT_MAX, it shall throw std::invalid_argument and leave the previous precision unchanged. The selected value shall be the square-root precision in 🔗 2. Finite rational square root at the selected irrational precision. In a thread-safe configuration, each thread shall own its parameter independently; in a non-thread-safe configuration, callers shall serialize reads, writes and calculations using the shared parameter. Clients shall keep the parameter stable throughout each dependent numerical call. Initialized thread lifetimes shall establish the default described in 🔗 3. Thread initialization, default state and finalization. These accessors themselves shall require no library or thread initialization owner, coefficient-constant stage or FPU setup, and shall preserve hardware rounding direction. |
Precision is an explicit numerical parameter, with a defined range and ownership rule. Changing it must neither silently truncate the requested value nor disturb unrelated native rounding state. |
|
|
|
|
|
Check zero, ordinary values and INT_MAX, then reject larger unsigned values with exactly std::invalid_argument and unchanged stored precision. Restore the caller parameter after testing. In thread-safe configurations, verify isolated values in independent workers without explicit initialization owners; serialize all non-thread-safe tests. Preserve hardware direction and exercise no-FPU configurations. |
src/checked_mpq_inlines.hh; src/checked.cc; src/Checked_Number_defs.hh and src/Checked_Number_inlines.hh; tests/squarerootspec1.cc. |
|
|
Public header: <ppl.hh>; PPL interfaces: unsigned irrational_precision(); void set_irrational_precision(unsigned p); |