Giving a True when it should be nil

Giving a True when it should be nil

marc_pepin
Contributor Contributor
1,176 Views
5 Replies
Message 1 of 6

Giving a True when it should be nil

marc_pepin
Contributor
Contributor

I got a routine with the line (/= (nth 4 item) 1.5) which return "T" for every real that (nth 4 item)  return even 1.5???

Does anyone ever experience that?

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

dbhunia
Advisor
Advisor

Hi

 

if (nth 4 item)  return 1.5???  (say 1.55555)

then (/= (nth 4 item) 1.5) means (/= 1.55555 1.5) always return "T"


Debashis Bhunia
Co-Founder of Geometrifying Trigonometry(C)
________________________________________________
Walking is the First step of Running, Technique comes Next....
0 Likes
Message 3 of 6

marko_ribar
Advisor
Advisor
Accepted solution

Your (nth 4 item) is not exactly 1.5... Check it with (rtos (nth 4 item) 2 50)... If it returns some numbers after 1.5, then your check is wrong, try changing it to (not (equal (nth 4 item) 1.5 fuzz))... If number from (nth 4 item) is in the fuzz range near 1.5 this fix should return valid check value - nil (not T)...

Marko Ribar, d.i.a. (graduated engineer of architecture)
0 Likes
Message 4 of 6

Kent1Cooper
Consultant
Consultant
Accepted solution

One of your values that displays as 1.5 may actually be 1.499999999999308 or 1.50000000000276 or something.  Comparing real numbers, which can result from various kinds of calculations and extractions that can have such tiny differences, should be done using the (equal) function with a fuzz factor:

 

(not (equal (nth 4 item) 1.5 1e-6))

Kent Cooper, AIA
0 Likes
Message 5 of 6

cadffm
Consultant
Consultant

They are not the same..

(Rtos (nth 4 item) 2 15) , is it 1.500000000000000 ?

 

Use function equal [F1]

Sebastian

0 Likes
Message 6 of 6

Kent1Cooper
Consultant
Consultant

@marko_ribar wrote:

.... (rtos (nth 4 item) 2 50) ....


 

[Don't bother with asking for 50 decimal places.  16 is the most you're ever going to wring out of it.]

Kent Cooper, AIA
0 Likes