Expr-LogicalOperators.xml 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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="1" frame="all" rowsep="1">
  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. </para>
  48. <para>If the probability of occurrence is known, you should order them
  49. from the most likely to occur to the least likely to occur, because once
  50. any part of a compound OR condition evaluates to TRUE, the remainder of
  51. the expression can be bypassed. However, this is not guaranteed. This is
  52. also true of the order of MAP function conditions.</para>
  53. <para>Whenever AND and OR logical operations are mixed in the same
  54. expression, you should use parentheses to group within the expression to
  55. ensure correct evaluation and to clarify the intent of the expression. For
  56. example consider the following:</para>
  57. <programlisting>isCurrentRevolv := trades.trd_type = 'R' AND
  58. trades.trd_rate = '0' OR
  59. trades.trd_rate = '1';</programlisting>
  60. <para>does not produce the intended result. Use of parentheses ensures
  61. correct evaluation, as shown below:</para>
  62. <programlisting>isCurrentRevolv := trades.trd_type = 'R' AND
  63. (trades.trd_rate = '0' OR trades.trd_rate = '1');</programlisting>
  64. </sect2>
  65. <sect2 id="An_XOR_Operator">
  66. <title>An XOR Operator<indexterm>
  67. <primary>XOR Operator</primary>
  68. </indexterm></title>
  69. <para>The following function can be used to perform an XOR operation on 2
  70. Boolean values:</para>
  71. <programlisting>BOOLEAN XOR(BOOLEAN cond1, BOOLEAN cond2) :=
  72. (cond1 OR cond2) AND NOT (cond1 AND cond2);</programlisting>
  73. </sect2>
  74. </sect1>