alijahed Posted February 17, 2011 Share Posted February 17, 2011 Hi All, I wrote a lisp and I get rounded results instead of actual real results. Because it is a long lisp I took out the part that create the rounded figure for me. firstly, I wrote an external function for ArcSin and I call it here as asin: (defun asin (x) (ATAN X (SQRT (- 1 (* X X)))) ) (defun c:test () (setq rad 4259.0623) ;Angle variables (setq angButt (* 2 (asin (/ (/ 8 2) rad)))) (setq angSinkless (* 2 (asin (/ (/ 4 2) rad)))) (print angButt) (print angSinkless) ;Arc length variables (setq arcButt (* angButt rad)) (setq arcSinkless (* angSinkless rad)) (print arcButt) (print arcSinkless) (princ) ) The result are: Command: test 0.00187835 0.000939174 8.0 4.0 Command: As you see I receive 8.0 and 4.0 the rounded figures.How can I fix this? Quote Link to comment Share on other sites More sharing options...
rkmcswain Posted February 17, 2011 Share Posted February 17, 2011 (rtos arcButt 2 16) Quote Link to comment Share on other sites More sharing options...
alijahed Posted February 17, 2011 Author Share Posted February 17, 2011 Thanks for your reply, I found the the rest of it on Help. Cheers Quote Link to comment Share on other sites More sharing options...
BIGAL Posted February 18, 2011 Share Posted February 18, 2011 Also lisp does some funy things somtimes if you use integers v's reals in your code / x 2 may give a different answer to / x 2.0 Quote Link to comment Share on other sites More sharing options...
alijahed Posted February 18, 2011 Author Share Posted February 18, 2011 problem!!! by using "rtos" I will receive the real number as "string" so I cannot do other calculations using that number. I know "atof" to convert that to real number but it is not the best way. Is there any way to force LISP to calculate with the highest precision which I think it is 16 digits? Quote Link to comment Share on other sites More sharing options...
alijahed Posted February 18, 2011 Author Share Posted February 18, 2011 I think Autolisp does the calculations up to 16 digits but when you ask it to print it rounds the figure. Quote Link to comment Share on other sites More sharing options...
MSasu Posted February 18, 2011 Share Posted February 18, 2011 The calculation is always done with maximum precision. When print as string, if you don't specify the number of decimals, the RTOS function will apply the value set by LUNITS system variable. This is the explanation of that rounding. So, don’t have to be afraid, that affects only the display of string – internally it is retained and used with maximum precision. Regards, Mircea Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.