Jump to content

Rounded figures!


alijahed

Recommended Posts

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?

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...