Greater than function accuracy issue

Greater than function accuracy issue

jmillerWL6P5
Participant Participant
372 Views
5 Replies
Message 1 of 6

Greater than function accuracy issue

jmillerWL6P5
Participant
Participant

I'm attempting to run a function that recognizes a variable as greater than the integer 1. The function looks as simple as this...

(setq z (/ l 240))

(if (> z 1)
(progn.... So on

 

If the variable that is being pulled has a value of 2 or higher, then the function works fine. If the value is less than 1, then the function acts as it's supposed to. The issue I'm having is any real number between 1.0 and 1.9999... If the z variable is pulling a real number that is 1.25, then the function recognizes  that as a False statement, and not proceeding as I intended it to. 

 

My question is this an error on my end, or is this how the greater than function works? The help page on the lisp states it compares real numbers and integers, so I don't think adjusting my variables to be the same type would matter; but I tried that anyway and it didn't work. Is the accuracy of real numbers to the nearest whole number, or can I adjust it's accuracy? I'm not looking for someone to write my lisp for me, but I've met a road block just before the finish line. I'd just like some clarification on this function and/or any other means to fix this issue.

 

I appreciate any help on the matter.

0 Likes
Accepted solutions (1)
373 Views
5 Replies
Replies (5)
Message 2 of 6

paullimapa
Mentor
Mentor

Would it make a difference to try this 

(> z 1.0)


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes
Message 3 of 6

jmillerWL6P5
Participant
Participant

Sadly no it doesn't. I've tried forcing the variable to be an integer, but that screws with the math i'm doing. I've made sure that both the variable and the value I'm comparing to are real numbers, but it doesn't seem to fix the issue either. It seems to me that the value can be whatever type I desire, but the accuracy is compares at it stuck at an integer level. I hope that makes sense.

0 Likes
Message 4 of 6

paullimapa
Mentor
Mentor

looks like your lisp interpreter crashed because I'm not experiencing this on my autocad:

paullimapa_0-1685116753038.png

 


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes
Message 5 of 6

jmillerWL6P5
Participant
Participant
Accepted solution

I made some test lisps isolating certain aspects of the code around the greater than function. The variable I was comparing was a result from a division function from a real number and an integer. I don't know how or why, but that made all difference. Sorry to waste your time with my question. Have a great day!

0 Likes
Message 6 of 6

john.uhden
Mentor
Mentor

@jmillerWL6P5 ,

At first I thought that the numerator was 1 (one), but I checked it in VLIDE and it's a lowercase L.  So if L is an integer and the divisor (240) is an integer (which it is) then the result would always be an integer.

F'rinstance (/ 241 240) = 1

Try changing your divisor to a real...

(/ 241 240.0) = 1.00417

John F. Uhden

0 Likes