AutoLISP subtration error

Discussion in 'AutoCAD' started by Cliff Davis, Jan 20, 2004.

  1. Cliff Davis

    Cliff Davis Guest

    Using the following code where line1 is a 180d line, the idea is to reduce it to 0 in order to compare it another line that I will
    be doing the same thing to.

    (setq *pi90* (* pi 0.5))

    ; to set the angle of the line assume 180d for my porpose
    (setq line1_angle (angle (dxf 10 (setq line1_list (entget line1))) (dxf 11 line1_list)))

    (while (>= line1_angle *pi90*) (setq line1_angle (- line1_angle *pi90*)))


    The problem is that "line1_angle" solves to
    1.33227e-015
    instead of 0.0.

    Is there a reason that this is not solving to 0.00, is this a known issue. Is there some known fix for this?
    Thanks
    Cliff
     
    Cliff Davis, Jan 20, 2004
    #1
  2. Cliff Davis

    Tom Berger Guest

    Yes. The reason is that no computer ever will have enough memory to
    store PI in full accuracy. And of course: no oldfashioned
    mathematician will ever have enough paper to write down PI to full
    accuracy.

    There is no difference between computer based math and paper based
    math: comparing results of calculations which are based on real
    numbers like PI will always have limited accuracy.
    Yes, of course.
    Compare with EQUAL and a fuzzy value to give a bandwidth for the
    accuracy which will fullfill your needs. Something like
    (equal PI 3.14 0.01)

    Tom Berger
     
    Tom Berger, Jan 20, 2004
    #2
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.