computable-reals icon indicating copy to clipboard operation
computable-reals copied to clipboard

approx vs print representation

Open mgi opened this issue 4 years ago • 1 comments

Hi,

In some code I'm writing I have to compare two creals. The code I'm using is the following:

(defun =r (a b precision)
  (let ((a (approx-r a precision))
        (b (approx-r b precision)))
    (unless (= a b) (break))
    (= a b)))

For some values, I end up in the debugger (with the break) but what is strange to me is that the backtrace (in sbcl BTW) shows me the following values for a and b:

Backtrace:
  0: (GEODESIC/TEST::=R +1.87802555827473610813... +1.87802555827473610814... 17)
      Locals:
        A = +1.87802555827473610813...
        A#1 = 246156
        B = +1.87802555827473610814...
        B#1 = 246157
        PRECISION = 17

So the printed representation of creals a and b seems to be the same up to the 19th decimal but their (approx-r x 17) are different.

I don't really understand creals internal representation so I don't know how to proceed from here.

mgi avatar Jun 30 '21 08:06 mgi

Ok, it seems to come from the fact that creal-print itself sets the creal precision to a much higher value then the one I have get with both approx-r calls.

For instance, the following works:

(defun =r (a b precision)
  (approx-r a (+ precision 9))
  (approx-r b (+ precision 9))
  (let ((a (approx-r a precision))
        (b (approx-r b precision)))
    (unless (= a b) (break))
    (= a b)))

Maybe it should be something that is handled in get-approx directly… don't know?

mgi avatar Jun 30 '21 14:06 mgi