tcuneio Posted December 8, 2010 Share Posted December 8, 2010 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?? Quote Link to comment Share on other sites More sharing options...
Michaels Posted December 8, 2010 Share Posted December 8, 2010 I have tried them and it returns 0 Could you please post all your codes to check them out for you ? Thanks Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted December 8, 2010 Share Posted December 8, 2010 Sounds like the problems stem from the rounding of doubles, try something like this: (equal mdr (fix mdr) 1e-10) Quote Link to comment Share on other sites More sharing options...
tcuneio Posted December 8, 2010 Author Share Posted December 8, 2010 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. Quote Link to comment Share on other sites More sharing options...
pBe Posted December 9, 2010 Share Posted December 9, 2010 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 Quote Link to comment Share on other sites More sharing options...
David Bethel Posted December 9, 2010 Share Posted December 9, 2010 Try this: (rtos mdr 2 16) It will give you the stored value bound to the variable. -David Quote Link to comment Share on other sites More sharing options...
tcuneio Posted December 9, 2010 Author Share Posted December 9, 2010 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. Quote Link to comment Share on other sites More sharing options...
tcuneio Posted December 9, 2010 Author Share Posted December 9, 2010 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! 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.