dxf <dxfo…@gmail.com> writes:
>On 30/10/2026 5:47 pm, Anton Ertl wrote:
>> dxf <dxfo…@gmail.com> writes:
>>> It's not clear to me that IEEE even talks in terms of 'representable' numbers >>> which leads to the junk that GCC et al print out: >>> >>> 5.1 Overview >>> >>> "Each of the computational operations that return a numeric result specified by >>> this standard shall be performed as if it first produced an intermediate result >>> correct to infinite precision and with unbounded range, and then rounded that >>> intermediate result, if necessary, to fit in the destination’s format"
>> >> This already says it: "if necessary". When the result is >> representable in the destination's format, rounding is not necessary. >> When the destination format is a string buffer with enough digits, >> rounding is not necessary, and the exact value can be shown.
...
>The example I gave - 2/3 to infinity >'correctly rounded' - starts failing at the 17th digit when stored in binary64.
The value 2/3 cannot be represented with finitely many decimal digits, nor with finitely many binary digits, and certainly not in binary64. So when you do, say 2e 3e f/ e.exact on Gforth (with, e.g., glibc 2.36), what happens is: 2e is converted to binary64, which can be done exactly, so no rounding is necessary. 3e likewise. f/ produces a result that cannot be represented exactly in binary64, so rounding is necessary, and happens. If you want to call anything "junk" because of lack of exactness, it should be the result of F/. e.exact prints the number it finds on the stack, exactly. Given that we know how 2/3 should look in decimal, the output of E.EXACT is useful for seeing how the result of F/ differs from the exact value. If you have no use for such information, use a different FP printing word, e.g., E. - anton