Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

approx vs print representation #4

Open
mgi opened this issue Jun 30, 2021 · 1 comment
Open

approx vs print representation #4

mgi opened this issue Jun 30, 2021 · 1 comment

Comments

@mgi
Copy link

mgi commented Jun 30, 2021

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
Copy link
Author

mgi commented Jun 30, 2021

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant