[comp.sys.mac.hypercard] Hypercard Numeric Comparison Errors

olson@endor.harvard.edu (Eric K. Olson) (05/12/89)

In my first attempt to do useful stuff with Hypercard, I have encountered
a very serious problem.  I'm hoping someone will just tell me I'm doing
something wrong:

Hypercard 1.2.2 seems to have a problem with numeric = and <> operators.
The following script:

on MouseUp
  set numberformat to "0.000000000000000000000000000000"
  put empty into cd fld 1
  repeat with x=1 to 30
    put 1/(10^x) into boo
    put boo && (boo = 0) && (boo <> 0) into line x of cd fld 1
  end repeat
end MouseUp

attached to a button, and with a card field available for it to put its
output, yields some very strange results (note that this must be run as
a script, because Hypercard resets numberformat on idle):

0.1 through 0.0000000001 yield the expected results:  false for =0, and
true for <>0.  BUT:

0.00000000001 yields false for both =0 and <>0 (an impossibility), and
numbers smaller than that yield true for =0 and false for <>0!

BUT:  all these numbers will yield true for >0 !!!

[Please note that I've expressed 0.00099999.... as 0.001 in these examples.
I don't think that that (binary/decimal conversion error) is the root of
this problem.  Try the script if you can't believe this!]

Hypercard clearly knows that these numbers are not zero.  They can be
calculated with, and they do return true for >0.  The only workaround
I can imagine is to use ((x<0) or (x>0)) for x<>0 and (not ((x<0) or (x>0)))
for x=0.

Is this fixed in a later release of Hypercard?  Am I doing something
wrong?  My apologies if this has been discussed before.

Other things that suprised me (but I'm not so worried about):

1.  Hypercard doesn't understand unary +, i.e., +323.33.
2.  Hypercard doesn't understand scientific notation, i.e., 3.233E+22.
3.  I can't trap errors like an undefined variable in "value of".  I got
    around this one by writing an XFCN that just calls back Hypercard
    to evaluate the argument (this allows me to trap the error without
    displaying a dialog).

Thanks in advance for your help!

-Eric



          Lexington Software Design:  Tomorrow's Software Yesterday

      Eric K. Olson     olson@endor.harvard.edu     harvard!endor!olson
         (Name)                (Arpanet)                 (Usenet)