From: Pasukhin Dmitry Date: Sat, 8 Nov 2025 14:12:16 +0000 (+0000) Subject: Foundation Classes - Add precision-related methods and descriptions in Precision... X-Git-Url: http://git.dev.opencascade.org/gitweb/?a=commitdiff_plain;h=bbdddd24d4985b7f009e1e3bef0f96ca68167d5e;p=occt.git Foundation Classes - Add precision-related methods and descriptions in Precision.hxx (#811) - Introduced new static constexpr methods: Computational() and SquareComputational() for machine epsilon precision. - Enhanced documentation to clarify the purpose and use cases of these methods in numerical computations. - Emphasized the distinction between machine epsilon and geometric tolerances for better understanding. --- diff --git a/src/FoundationClasses/TKernel/Precision/Precision.hxx b/src/FoundationClasses/TKernel/Precision/Precision.hxx index d08f7c0148..b66e46b0ef 100644 --- a/src/FoundationClasses/TKernel/Precision/Precision.hxx +++ b/src/FoundationClasses/TKernel/Precision/Precision.hxx @@ -168,6 +168,33 @@ public: //! Created for speed and convenience. static constexpr Standard_Real SquareConfusion() { return Confusion() * Confusion(); } + //! Returns a precision value at machine epsilon level, used for + //! low-level numerical computations and floating-point comparisons. + //! Unlike the geometric tolerances (Confusion, Intersection, Approximation) + //! which are application-level values for modeling operations, this value + //! represents the fundamental limit of floating-point arithmetic precision. + //! + //! Typical use cases include: + //! - Checking if squared magnitudes are effectively zero (e.g., vector.SquareMagnitude() < + //! SquareComputational()) + //! - Division-by-zero protection in numerical algorithms + //! - Convergence criteria in iterative solvers at machine precision level + //! - Detecting numerical degeneracies in low-level computations + //! + //! The computational tolerance is equal to DBL_EPSILON (approximately 2.22e-16), + //! which is the smallest positive value such that 1.0 + eps != 1.0 in double + //! precision floating-point arithmetic. This is the fundamental machine epsilon + //! for Standard_Real (double) type. + //! + //! Note: This value should NOT be used for geometric comparisons. + //! Use Precision::Confusion() for comparing geometric distances, + //! Precision::Angular() for angles, etc. + static constexpr Standard_Real Computational() { return RealEpsilon(); } + + //! Returns square of Computational. + //! Created for speed and convenience when comparing squared values. + static constexpr Standard_Real SquareComputational() { return Computational() * Computational(); } + //! Returns the precision value in real space, frequently //! used by intersection algorithms to decide that a solution is reached. //! This function provides an acceptable level of precision