Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
v3:expressions [2023/09/03 08:53] neilsv3:expressions [2024/07/30 22:51] (current) neils
Line 2: Line 2:
  
 When no parentheses are present, arithmetic expressions are evaluated from left to right, with multiplication and division having a higher priority than addition and subtraction. When no parentheses are present, arithmetic expressions are evaluated from left to right, with multiplication and division having a higher priority than addition and subtraction.
 +
 +The following table explains operator precedence in XC=BASIC:
  
 | Highest    | ''NOT'', ''-'' (unary) | | Highest    | ''NOT'', ''-'' (unary) |
Line 9: Line 11:
 | Lowest    | ''AND'', ''OR'', ''XOR'' | | Lowest    | ''AND'', ''OR'', ''XOR'' |
  
-The arithmetic operators, ''+'', ''-'', ''*'', and ''/'', work in the expected fashion, however, the result of arithmetic on type BYTE, WORD or INT cannot have a fractional result. Therefore ''5 / 2'' evaluates as 2, not 2.5. However, ''5.0 / 2.0'' evaluates as 2.5, because the presence of the decimal point tells the compiler that the numbers are of type FLOAT.+The arithmetic operators, ''+'', ''-'', ''*'', and ''/'', work in the expected fashion, however, the result of arithmetic on type BYTE, WORDINT or LONG cannot have a fractional result. Therefore ''5 / 2'' evaluates as 2, not 2.5. However, ''5.0 / 2.0'' evaluates as 2.5, because the presence of the decimal point tells the compiler that the numbers are of type FLOAT.
  
   PRINT 5/2 ' Outputs 2   PRINT 5/2 ' Outputs 2