Visual LISP, AutoLISP and General Customization

Visual LISP, AutoLISP and General Customization

Reply
*Expert Elite*
_gile
Posts: 2,082
Registered: ‎04-29-2006
Message 11 of 14 (122 Views)

Re: Strange behavior from polar function in LISP

03-20-2014 03:47 PM in reply to: Lee_Mac

>> (approximately 15 decimal places for double precision floating point values)


Not 15 decimal places, but 15 significant digits, as shown the following examples

 

12345678901234500000 (0 decimal places)
1234567890.12345 (5 decimal places)

1.23456789012345 (14 decimal places)

0.000000000123456789012345 (25 decimal places)

 

 Therefore the accuracy is lost gradually as going away from the origin (as in some land survey drawings).
Gilles Chanteau
*Expert Elite*
Lee_Mac
Posts: 1,141
Registered: ‎12-29-2009
Message 12 of 14 (120 Views)

Re: Strange behavior from polar function in LISP

03-20-2014 03:50 PM in reply to: _gile

Good catch gile - thanks.

Lee Mac ProgrammingTwitterExchange App StoreDropbox (500MB free)
Expert Elite
With Mathematics there is the possibility of perfect rigour, so why settle for less?
*Expert Elite*
_gile
Posts: 2,082
Registered: ‎04-29-2006
Message 13 of 14 (96 Views)

Re: Strange behavior from polar function in LISP

03-21-2014 01:13 PM in reply to: Lee_Mac

I tried something to automatically compare numbers and points with a tolerance which takes in account the significant digits (not deeply tested).

 

(defun log10 (x)
  (if (zerop x)
    0.0
    (/ (log (abs x)) (log 10))
  )
)

(defun fuzz (x)
  (expt 10.0 (- (fix (log10 x)) 14))
)

(defun equalNumbers (x y)
(or (= x y) (equal x y (max (fuzz x) (fuzz y)))) ) (defun equalPoints (p1 p2) (vl-every 'equalNumbers p1 p2) )

(fuzz 0.0000123456789012345) =>1.0e-018
(fuzz 0.123456789012345) =>1.0e-014
(fuzz 12345.6789012345) =>1.0e-010
(fuzz 1234567890.12345) =>1.0e-005
(fuzz 123456789012345) =>1.0

Gilles Chanteau
*Expert Elite*
_gile
Posts: 2,082
Registered: ‎04-29-2006
Message 14 of 14 (78 Views)

Re: Strange behavior from polar function in LISP

03-22-2014 10:24 AM in reply to: _gile

Here's a more mathematically rigorous implementation:

 

(defun gc:Log10 (x)
  (/ (log x) (log 10))
)

(defun gc:Fuzz (x)
  (if (zerop x)
    1e-15
    (expt 10.0 (fix (- (gc:Log10 (abs x)) 15)))
  )
)

(defun gc:EqualNumbers (x y)
  (or (= x y) (equal x y (max (gc:Fuzz x) (gc:Fuzz y))))
)

(defun gc:EqualPoints (p1 p2)
  (vl-every 'gc:EqualNumbers p1 p2)
)

 

 

Gilles Chanteau
Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.
Need installation help?

Start with some of our most frequented solutions or visit the Installation and Licensing Forum to get help installing your software.