Jump to content

simple expression problems


tcuneio

Recommended Posts

I'm getting some strange results from expressions. I'm new to LISP so this will hopefully be painfully obvious to someone but it's driving me nuts.

 

If (rem 10.0 2) is 0 and variable mdr is 5.0, then way does (rem (* 2 mdr) 2) yield 2 instead of 0?

 

Also my expression (equal mdr (fix mdr)) when variable mdr is 5.0 yields nil.

 

Both these functions seem to work most of the time. What am I missing??

Link to comment
Share on other sites

Sounds like the problems stem from the rounding of doubles, try something like this:

 

(equal mdr (fix mdr) 1e-10)

 

I tried the fuzz and it didn't work. It must have something to do with my variable MDR. When I query the varible (!mdr) at the command line, it yields 5.0. If I then type (fix mdr) it yeilds 4. If I then (setq mdr 5.0) and run (fix mdr) it gives 5. Something similar is happening with my REM function.

 

Michael requested me to post my code which will be my next plan, but I have about 6 pages of code at this point so I'll have to try and edit out the portions that are relevant.

Link to comment
Share on other sites

If (rem 10.0 2) is 0 and variable mdr is 5.0, then way does (rem (* 2 mdr) 2) yield 2 instead of 0?

 

you will get 2 if you had it this way

 

(rem  2 (* 2 mdr)):,--- 2 before the arg

 

 

When I query the varible (!mdr) at the command line, it yields 5.0. If I then type (fix mdr) it yeilds 4. If I then (setq mdr 5.0) and run (fix mdr) it gives 5. Something similar is happening with my REM function.

 

I suspect it has something to do with localising your variable thats why you're getting varying results

 

e.g.

(setq mdr 5.0);<---------- value of mdr prior to running the code (testing phase perhaps)
(defun c:test (/ mdr)
(setq mdr (getreal "\nEmter Value: "))
(print (fix mdr))(princ)
 )

 

Command: TEST

Emter Value: 4

4

Command: !MDR

5.0

Command: (fix mdr)

5.0

 

 

 

 

:unsure:

Link to comment
Share on other sites

Try this:

(rtos mdr 2 16)

It will give you the stored value bound to the variable. -David

 

I get 4.999999... This is what I suspected but didn't know how to query the variable. Thank you very much. It looks like I need to clean up my input into the mdr list and that should solve it. It was confusing since the command line query !mdr gave 5.0. It obviously rounds. Thanks again.

Link to comment
Share on other sites

Just wanted to say thanks to everyone who took the time to look at this problem. I'm now using Michael's rnd2nea function to clean up my input data so I don't get stuck on minor measurement errors when picking points. Thanks!

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...