J3/04-115 Date: 08 Dec. 2003 To: J3 From: Dan Nagle Subject: New Intrinsic ULPS Many times, the question arises: How to code when two reals are almost equal? Schemes using epsilon or spacing ask the question whether the two reals are within a preset distance of each other. To come at the question the other way 'round, a new intrinsic is required. I propose the ULPS intrinsic. Number: Title: ULPS Submitted By: J3 Status: For Consideration References: Basic Functionality: Return the number of units of least precision between two real numbers of the same kind. Rationale: A preset test may be coded using intrinsics available today to ask whether two reals of the same kind are within a pre-selected distance of each other. But no easy way exists to ask how far apart they are. A ULPS intrinsic would do so. It would take two reals of the same kind and return a real of the same kind whose value if the count of ulps between the two. The result is infinite if the two reals differ in sign, or if one is zero. Estimated Impact: One more intrinsic to be written and supported, but it's only a few lines of code. Detailed Specification: New Intrinsic ULPS( X, Y) Real X, Y same kind. Result: Real of same kind as X, Y. Number of units of least precision between X and Y; infinity if X, Y differ in sign or either is zero or Infinity. NaN is either or both is/are NaN(s). Example: logical :: approximately_equal approximately_equal = abs( ulps( X, Y)) < tolerance History: