Expr-LogicalOperators.xml 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!DOCTYPE sect1 PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN"
  3. "http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd">
  4. <sect1 id="Logical_Operators">
  5. <title>Logical Operators</title>
  6. <para><emphasis>The following </emphasis>logical operators<indexterm>
  7. <primary>logical operators</primary>
  8. </indexterm> are supported, listed here in their evaluation
  9. precedence:</para>
  10. <informaltable colsep="0" frame="none" rowsep="0">
  11. <tgroup align="left" cols="2">
  12. <colspec colwidth="94.80pt" />
  13. <colspec />
  14. <tbody>
  15. <row>
  16. <entry>NOT</entry>
  17. <entry>Boolean NOT<indexterm>
  18. <primary>Boolean NOT</primary>
  19. </indexterm> operation</entry>
  20. </row>
  21. <row>
  22. <entry>~</entry>
  23. <entry>Boolean NOT<indexterm>
  24. <primary>Boolean NOT</primary>
  25. </indexterm> operation</entry>
  26. </row>
  27. <row>
  28. <entry>AND</entry>
  29. <entry>Boolean AND<indexterm>
  30. <primary>Boolean AND</primary>
  31. </indexterm> operation</entry>
  32. </row>
  33. <row>
  34. <entry>OR</entry>
  35. <entry>Boolean OR<indexterm>
  36. <primary>Boolean OR</primary>
  37. </indexterm> operation</entry>
  38. </row>
  39. </tbody>
  40. </tgroup>
  41. </informaltable>
  42. <para></para>
  43. <sect2 id="Logical_Expression_Grouping">
  44. <title>Logical Expression Grouping</title>
  45. <para>When a complex logical expression has multiple OR conditions, you
  46. should group the OR conditions and order them from least complex to most
  47. complex to result in the most efficient processing. If the probability of
  48. occurrence is known, you should order them from the most likely to occur
  49. to the least likely to occur, because once any part of a compound OR
  50. condition evaluates to TRUE, the remainder of the expression is bypassed.
  51. This is also true of the order of MAP function conditions.</para>
  52. <para>Whenever AND and OR logical operations are mixed in the same
  53. expression, you should use parentheses to group within the expression to
  54. ensure correct evaluation and to clarify the intent of the expression. For
  55. example consider the following:</para>
  56. <programlisting>isCurrentRevolv := trades.trd_type = 'R' AND
  57. trades.trd_rate = '0' OR
  58. trades.trd_rate = '1';</programlisting>
  59. <para>does not produce the intended result. Use of parentheses ensures
  60. correct evaluation, as shown below:</para>
  61. <programlisting>isCurrentRevolv := trades.trd_type = 'R' AND
  62. (trades.trd_rate = '0' OR trades.trd_rate = '1');</programlisting>
  63. </sect2>
  64. <sect2 id="An_XOR_Operator">
  65. <title>An XOR Operator<indexterm>
  66. <primary>XOR Operator</primary>
  67. </indexterm></title>
  68. <para>The following function can be used to perform an XOR operation on 2
  69. Boolean values:</para>
  70. <programlisting>BOOLEAN XOR(BOOLEAN cond1, BOOLEAN cond2) :=
  71. (cond1 OR cond2) AND NOT (cond1 AND cond2);</programlisting>
  72. </sect2>
  73. </sect1>