Unibasic BUG? 
Author Message
 Unibasic BUG?


 > Date: Thu, 26 Jan 1995 16:14:37 MST
 > What should the output of this program be?
 >
 > A="1"
 > IF A = "1"   THEN PRINT "X"
 > IF A = "01" THEN PRINT "Y"
 >
 > In Unidata 3.1.5b both the X and the Y  are printed.
 > I always thought that since the above code is comparing strings
 > that the output would be X
 >
 > It seems weird to me that Unidata/Unibasic compares strings,
 > that happen to be numeric, as a numeric.

*** Short Answer ***

To prevent a numeric comparison of the values of the two expressions
expr1 and expr2, and to force a string comparison of the values, just
compare ("X" : expr1) with ("X" : expr2), and you will
then find that "X01" is not equal to "X1".

*** Rainbow Answer ***

From the rainbow-covered REALITY (R) Data/Basic (TM) Reference Manual.
(C) 1976, Microdata Corporation.

Chapter 2, Elements of the Data/Basic Language.

Section 2.3, Arithmetic Expressions.

"The simplest arithmetic expression is a single numeric constant ...
... if a string value containing only numeric characters is used
in an arithmetic expression, it is considered as a decimal number."

Section 2.5, Relational Expressions.

"An arithmetic relation is a pair of arithmetic expressions
separated by any one of [the] relational operators ...
... A string relation is a pair of string expressions separated
by any one of the relational operators.  A string relation may also
be a string expression and an arithmetic expression separated by
a relational operator (i.e., if a relational operator encounters
one numeric operand and one string operand, it treats both operands
as strings)."

[one notes that the word "relation" wasn't so overloaded, back then]

*** Long Answer ***

At compile time, the literals within quotes are parsed and compiled
as strings, which is not to imply that Mr. Palatrone's UniBasic (R)
program is comparing strings, but just to observe that UniBasic is
comparing, at run-time, the values of some expressions which were
declared, at compile-time, as strings.

At run-time, when UniBasic is comparing the values of two expressions,
UniBasic doesn't care whether an operand's value came from a string
declaration, from a numeric declaration, from a string operation, or
from a numeric operation.

No matter what declared or generated the values of the two operands
in a comparison, the general rule for comparing the values of
expressions expr1 and expr2 is

  IF expr1 # "" AND expr2 # "" AND NUM(expr1) AND NUM(expr2) THEN
    compare two floating point numbers
  END ELSE
    compare two strings
  END

UniQuery WITH and WHEN comparisons have a similar general rule,
if comparing a Right-justified attribute to another attribute
or to a literal constant, and/or if UDT.OPTIONS 22 is OFF.

The UDT.OPTIONS verb has some switches which may be used to
maintain compatibility with a variety of legacy environments.
For instance, "UDT.OPTIONS 10 ON" sets a compile-time switch
to do a TRIM() before doing a NUM() test, in which case
not only does "01" equal "1", but also " 1" equals "1".
... and if that's not what you want, see "Short Answer", above.

regards,
Uncle Ben
--
Ben Rosenberg * Unidata, Inc., Tech Support, Eastern Region
+1 609 695.0370 * Vmail



Mon, 21 Jul 1997 17:59:50 GMT  
 
 [ 1 post ] 

 Relevant Pages 

1. UniBasic

2. Business Basic (Unibasic 'N' : Nixdorf)

3. Unibasic

4. unibasic, iris business basic

5. ICONV function in UniBasic

6. UNIBASIC, PIC BASIC or Business Basic?

7. IDE BUGs, BUGs, BUGs....

8. BUGS BUGS BUGS!

9. Project98 OLE & VB: bugs, bugs, bugs

10. Stange String Behavior - Bug or Bugged ?

11. My Bug or VB.Net Bug ???

12. Anti-Bug If/Then Makes a Bug

 

 
Powered by phpBB® Forum Software