[comp.sys.handhelds] What's the difference?

b2676870@soph.cs.ubc.ca (George Chow) (06/27/91)

I've ran across a curious behaviour that I can't explain. I've RTFM and I still
can't see why.

Consider the following fragment:

  # 80000000 h SRB SRB SRB # C0 h AND # 80 h SAME

With word size > 32, the above evaluates to 1 (as expected). However, with
word size = 32, the above evalutes to 0. Why is this the case? As I recall,
the 48's binary integer are unsigned so there's no hidden sign extension. And
I'm using shifts, not rotates. 

The above fragment came up as a problem case for a quickie program I wrote to
decode IP addresses.

George 

stevev@greylady.uoregon.edu (Steve VanDevender) (06/27/91)

>Consider the following fragment:

>  # 80000000 h SRB SRB SRB # C0 h AND # 80 h SAME

>With word size > 32, the above evaluates to 1 (as expected). However, with
>word size = 32, the above evalutes to 0. Why is this the case?

I just tried this with word size == 64, and got a result of #80h
that was a 16-nibble binary integer.  With word size == 32, the
result of #80h was an 8-nibble binary integer.  They compare
unequal with SAME because they are not the same object.  They do
compare the same with == because they do have the same value.
This is reminiscent of the difference between (eq foo bar) and
(equal foo bar) in LISP--eq compares the objects to see if they
are the same (reside at the same address) while equal compares
them to see if they evaluate to the same value.  SAME compares
the binary representation of the objects while == compares their
visible values.

--
Steve VanDevender 	stevev@greylady.uoregon.edu
"Bipedalism--an unrecognized disease affecting over 99% of the population.
Symptoms include lack of traffic sense, slow rate of travel, and the
classic, easily recognized behavior known as walking."

herman@corpane.uucp (Harry Herman) (06/29/91)

In <STEVEV.91Jun26213922@greylady.uoregon.edu> stevev@greylady.uoregon.edu (Steve VanDevender) writes:

>>Consider the following fragment:

>>  # 80000000 h SRB SRB SRB # C0 h AND # 80 h SAME

>>With word size > 32, the above evaluates to 1 (as expected). However, with
>>word size = 32, the above evalutes to 0. Why is this the case?

>I just tried this with word size == 64, and got a result of #80h
>that was a 16-nibble binary integer.  With word size == 32, the
>result of #80h was an 8-nibble binary integer.  They compare
>unequal with SAME because they are not the same object.  They do
>compare the same with == because they do have the same value.
>This is reminiscent of the difference between (eq foo bar) and
>(equal foo bar) in LISP--eq compares the objects to see if they
>are the same (reside at the same address) while equal compares
>them to see if they evaluate to the same value.  SAME compares
>the binary representation of the objects while == compares their
>visible values.

>--
>Steve VanDevender 	stevev@greylady.uoregon.edu
>"Bipedalism--an unrecognized disease affecting over 99% of the population.
>Symptoms include lack of traffic sense, slow rate of travel, and the
>classic, easily recognized behavior known as walking."

However, the HP48 Programmer's Reference Manual states that SAME and ==
are supposed to work the same for any comparison that does not include
algebraics or a name.  (pgs 323 and 447).  In fact SAME said it is
"identical in effect to ==" except for those two types.

				Harry Herman
				herman@corpane

stevev@greylady.uoregon.edu (Steve VanDevender) (06/29/91)

>However, the HP48 Programmer's Reference Manual states that SAME and ==
>are supposed to work the same for any comparison that does not include
>algebraics or a name.  (pgs 323 and 447).  In fact SAME said it is
>"identical in effect to ==" except for those two types.

Despite what the Programmer's Reference Manual or the Owner's
Manual (volume II, p. 492 says basically the same thing you
cited), it is clear that SAME compares the binary representations
of binary integers and not just their values.  I have just done
some double-checking and seen that when you enter a binary
integer, it is placed on the stack as a 16-nibble binary integer.
However, if the word size is 60 or less then the result of a
binary integer operation is a binary integer with length
CEIL(RCWS / 4).  SAME does _not_ compare binary integers for
value equality but instead compares them for binary
equality--they must have the same length and the same value to
compare equal.  ==, however, does compare binary integers just
for value equality and is therefore the operator that has the
effect the original poster was looking for.

You can try this at home, like I did:

16 STWS
#8000h SRB #80 SAME produces the result 0
LASTARG == produces the result 1

You can replace the 16 with any number 60 or less and you will
get the same results.  If the number is greater than 60 then
results of binary integer operations will produce 16-nibble
binary integers and the second binary integer entered will
compare the same with SAME or == because both are 16-nibble
binary integers.

>				Harry Herman
>				herman@corpane

Shouldn't that be "herman@corpane.uucp" or "corpane!herman" or
something like that?

--
Steve VanDevender 	stevev@greylady.uoregon.edu
"Bipedalism--an unrecognized disease affecting over 99% of the population.
Symptoms include lack of traffic sense, slow rate of travel, and the
classic, easily recognized behavior known as walking."