Author Topic: Has anyone seen this before?  (Read 4166 times)

0 Members and 1 Guest are viewing this topic.

Water Bear

  • Guest
Has anyone seen this before?
« on: February 03, 2004, 05:46:05 PM »
I set the same point to different variables, then compared them in an IF statement...it says they are not equal! (note the watch) :shock:






 This IF is followed by a conditional which gives me the incorrect option because this IF fails. what gives?

daron

  • Guest
Has anyone seen this before?
« Reply #1 on: February 03, 2004, 05:48:57 PM »
Would replacing = with eq or equal help?

Matt Stachoni

  • Guest
Has anyone seen this before?
« Reply #2 on: February 03, 2004, 06:03:30 PM »
You can see in the watch window that the two values "look" similar, but in actuality are not if they were expanded to 15 significant digits. The = function tests numerical equality and they _have+ to be exactly equal to get T.

Using (equal num1 num2 fuzz) would be what you want to do here. Set fuzz to a very small number (0.000001) and try it.

Water Bear

  • Guest
Has anyone seen this before?
« Reply #3 on: February 03, 2004, 06:06:05 PM »
yep..that did the trick! thanx

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Has anyone seen this before?
« Reply #4 on: February 03, 2004, 06:06:49 PM »
When is equal not equal?
They are not the same (= eq equal)

I find (equal) to be the most forgiving and if that is not enough
you can use the fuzz factor.

Avoid using = on points.

Quote
Equal

Determines whether two expressions are equal
(equal expr1 expr2 [fuzz])

A real number defining the maximum amount by which expr1 and expr2 can differ and still be considered equal.

When comparing two real numbers (or two lists of real numbers, as in points), the two identical numbers can differ slightly if different methods are used to calculate them. You can specify a fuzz amount to compensate for the difference that may result from the different methods of calculation.



Quote
=
(equal to) Compares arguments for numerical equality



Quote
eq
Determines whether two expressions are identical
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

daron

  • Guest
Has anyone seen this before?
« Reply #5 on: February 03, 2004, 06:08:01 PM »
By three witnesses, the truth shall be known.

SMadsen

  • Guest
Has anyone seen this before?
« Reply #6 on: February 05, 2004, 06:16:18 AM »
Quote from: CAB
Avoid using = on points

Exactly.
"=" is for numbers, strings and symbol names, and that's it.

(setq a '("a" "b" "c" 1 2.0))
("a" "b" "c" 1 2.0)

(setq b '("a" "b" "c" 1 2.0))
("a" "b" "c" 1 2.0)

Are these lists equal to each other? Certainly, they seem to be but ...

(= a b) -> nil

Each item may be tested T with "=",

(mapcar '= a b) -> (T T T T T)

because it is testing what it's designed to do: numbers and strings. But comparing lists with it is no good.

EQ will also "fail" the test:

(eq a b) -> nil

EQ is comparing bindings, which means that a and b need to be bound to the same thing in order to be found equal. In this case, each list was build separately and has nothing to do with each other internally. Binding variables to the same object will make them equal in the eyes of EQ:

(setq c a)
("a" "b" "c" 1 2.0)

(eq a c) -> T

Only EQUAL compares lists by their literal contents:

(equal a b) -> T

By the way, using "=" to compare the variables after they have been bound to the same list will return T, which can cause one to think that EQ and "=" are alike:

(= a c) -> T

But try using them on, say, entity names:

(setq e1 (entlast))
<Entity name: 7ef5ce90>

(setq e2 (entlast))
<Entity name: 7ef5ce90>

e1 and e2 will be bound to the same physical object in memory, so EQ returns T:

(eq e1 e2) -> T

But "=" returns nil even though the objects are identical. It is not designed to handle those data types:

(= e1 e2) -> nil