C++ finite scalar sign and ordering
For the eleven standard native integer types, mpz_class, canonical finite mpq_class and their admitted checked wrappers, the named comparison functions shall compare the exact mathematical entry values, including operands of different scalar types. Signedness and storage width shall not replace mathematical ordering: a negative signed integer shall be less than every nonnegative unsigned integer, and unbounded integers and rational fractions shall retain their exact values.
cmp(x, y) shall return an int with negative, zero or positive sign exactly when x < y, x = y or x > y. Its nonzero magnitude shall not be prescribed. equal, not_equal, less_than, less_or_equal, greater_than and greater_or_equal shall return true exactly for their named mathematical relations. The corresponding six PPL comparison operators shall have the same meanings when at least one operand is a checked scalar. This operator guarantee shall not alter the built-in operators between two raw native integer types.
sgn(x) shall return exactly -1, 0 or 1 according to the mathematical value's sign. The configured coefficient and raw rational query contracts shall retain 🔗 1. Integral coefficient representation access and sign comparison and 🔗 9. Finite rational sign, comparison and numeric classification. Operands may be the same object. All these queries shall preserve source values, perform no policy result-handler dispatch and require no rounding default. They shall admit every finite representable value allowed by each operand's policy, including ordinary native integer minima and maxima. Checked policies shall provide the backend's relevant classification and representation traits.
Objects shall be live; rational values shall be canonical with positive denominator. Resources shall suffice for exact comparison and temporaries. Callers shall synchronize queries with overlapping object modification and serialize shared numerical temporaries in non-thread-safe builds. These exact scalar queries shall require no library initialization, coefficient constants or FPU rounding setup, and shall preserve hardware direction.
Mathematical ordering shall remain exact across signed, unsigned, bounded, unbounded and rational representations, without an intermediate narrowing conversion or policy exception decision.
Public header: <ppl.hh>; effective instantiations in PPL for admitted scalar types X and Y:
int sgn(const X& x); int cmp(const X& x, const Y& y); bool equal(const X& x, const Y& y); bool not_equal(const X& x, const Y& y); bool less_than(const X& x, const Y& y); bool less_or_equal(const X& x, const Y& y); bool greater_than(const X& x, const Y& y); bool greater_or_equal(const X& x, const Y& y);
The operators ==, !=, <, <=, > and >= shall be admitted when at least one argument is checked.
Cross every admitted native integer/GMP scalar type pair with independent integer/rational ordering oracles. Include both signedness directions, minima/maxima, values just outside native ranges, huge unbounded values and fractions on both sides of integers. Exercise raw/checked operand combinations, all named predicates and checked comparison operators, same-object relations, sign queries, source preservation and absence of handler calls under all hardware modes and coefficient profiles.
src/Checked_Number_defs.hh; src/Checked_Number_inlines.hh; src/checked_inlines.hh; src/checked_ext_inlines.hh; src/checked_mpz_inlines.hh; tests/scalarorderingspec1.cc; tests/numericpublic1.cc.
For one configured supported native floating operand and one exact scalar from 🔗 1. Exact scalar sign and ordering, including their admitted checked wrappers, cmp and the six named comparison predicates shall compare their exact mathematical entry values. The floating value shall mean its exactly stored binary value; a nearby decimal or integral value shall not be substituted. The PPL comparison operators shall have those same relation meanings when at least one operand is checked.
A large integer shall not be rounded to the floating operand's precision before deciding equality or order. Likewise, a finite rational shall retain its numerator/denominator value. Opposite signed floating zeros shall both compare as mathematical zero. Argument order shall not change equality or the mathematical relation: reversing arguments shall reverse strict order. These comparisons shall not invoke policy result handlers or use rounding defaults. Both argument objects shall remain unchanged. Floating/floating ordering shall retain 🔗 4. Ordered comparison of finite native floating-point values.
All operands shall be finite and valid for their selected policies, with canonical positive-denominator rational storage. Exact resources, synchronization and shared-temporary serialization shall follow 🔗 1. Exact scalar sign and ordering. General mixed comparisons shall require upward hardware rounding for their directed conversion filters, and preserve that direction. Native floating conversions and strict result queries shall have the backend/setup prerequisites of 🔗 1. Directed native integral conversion to native floating-point storage and 🔗 4. Directed narrowing between finite native floating-point formats; no coefficient-constant stage shall be required. Available resources shall permit any exact conversion or temporary needed by the comparison.
A comparison shall preserve distinctions that a floating conversion could round away, while retaining the actual represented floating value rather than an intended decimal approximation.
Public header: <ppl.hh>; effective instantiations in PPL for admitted mixed floating/exact scalar arguments:
int cmp(const X& x, const Y& y); bool equal(const X& x, const Y& y); bool not_equal(const X& x, const Y& y); bool less_than(const X& x, const Y& y); bool less_or_equal(const X& x, const Y& y); bool greater_than(const X& x, const Y& y); bool greater_or_equal(const X& x, const Y& y);
Either argument order shall be admitted. PPL ==, !=, <, <=, > and >= shall be admitted when at least one argument is checked.
Use independent significand/exponent extraction to convert finite floating corpus values to exact rational oracles. Cross all supported floating formats with each exact scalar type in both operand orders and raw/checked forms. Include signed zero, subnormals, range endpoints, integral precision boundaries, adjacent floating values, and exact fractions on either side of binary values. Check all relation interfaces, source preservation and no handler calls under caller-owned upward hardware rounding, restoring the caller's previous mode afterward.
src/Checked_Number_defs.hh; src/Checked_Number_inlines.hh; src/checked_inlines.hh; src/checked_ext_inlines.hh; src/checked_mpz_inlines.hh; tests/scalarorderingspec1.cc; tests/numericpublic1.cc.