Parma Polyhedra Library requirements
C++ native and rational square roots and irrational precision
PPL-SPEC-000501
1. Directed and delegated square root of a finite native value PPL-SPEC-000501

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.

2. Finite rational square root at the selected irrational precision PPL-SPEC-000502

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.

3. Selection and ownership of irrational rational precision PPL-SPEC-000503

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.