arithmetic

Realiza un cálculo aritmético de dos números (un número del lado izquierdo y un número del lado derecho) y opcionalmente redondea el resultado al número especificado de decimales.

Las operaciones soportadas son:

Si es necesario redondear, debe especificar:

aviso: Para las operaciones de división, en general se debe proporcionar una modalidad de redondeo y un número de decimales. Si no se proporciona y no se puede calcular un resultado exacto en el tiempo de ejecución, se producirá un error de tiempo de ejecución.

El validador de conjunto de reglas CER emitirá un aviso si detecta cualquier operación de división en el conjunto de reglas que no especifica redondeo.

<?xml version="1.0" encoding="UTF-8"?>
<RuleSet name="Example_arithmetic"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:noNamespaceSchemaLocation=
"http://www.curamsoftware.com/CreoleRulesSchema.xsd">
  <Class name="ArithmeticExampleRuleClass">

    <!-- 3 + 2 = 5 -->
    <Attribute name="addANumberToAnother">
      <type>
        <javaclass name="Number"/>
      </type>
      <derivation>
        <arithmetic operation="+">
          <Number value="3"/>
          <Number value="2"/>
        </arithmetic>
      </derivation>
    </Attribute>

    <!-- 3 - 2 = 1 -->
    <Attribute name="subtractANumberFromAnother">
      <type>
        <javaclass name="Number"/>
      </type>
      <derivation>
        <arithmetic operation="-">
          <Number value="3"/>
          <Number value="2"/>
        </arithmetic>
      </derivation>
    </Attribute>

    <!-- 3 * 2 = 6 -->
    <Attribute name="multiplyANumberByAnother">
      <type>
        <javaclass name="Number"/>
      </type>
      <derivation>
        <arithmetic operation="*">
          <Number value="3"/>
          <Number value="2"/>
        </arithmetic>
      </derivation>
    </Attribute>

    <!-- 3 / 2 = 1.5 -->
    <!-- Puesto que la división es por 2,
         podemos salir sin redondeo.
         De todas maneras el validador de conjunto
         de reglas CER emitirá un aviso.   -->
    <Attribute name="divideANumbersByAnother">
      <type>
        <javaclass name="Number"/>
      </type>
      <derivation>
        <arithmetic operation="/">
          <Number value="3"/>
          <Number value="2"/>
        </arithmetic>
      </derivation>
    </Attribute>

    <!-- (3 + 2) * 4 = 20 -->
    <Attribute name="chainedArithmetic">
      <type>
        <javaclass name="Number"/>
      </type>
      <derivation>
        <arithmetic operation="*">
          <arithmetic operation="+">
            <Number value="3"/>
            <Number value="2"/>
          </arithmetic>
          <Number value="4"/>
        </arithmetic>
      </derivation>
    </Attribute>

    <!-- 1,23 + 3,45 = 4,68,
         = 4,7 cuando se redondea al decimal más cercano-->
    <Attribute name="roundedAddition">
      <type>
        <javaclass name="Number"/>
      </type>
      <derivation>
        <arithmetic decimalPlaces="1" operation="+"
          rounding="half_up">
          <Number value="1.23"/>
          <Number value="3.45"/>
        </arithmetic>
      </derivation>
    </Attribute>

    <!-- 2 / 3, = 0,667 a 3 decimales -->
    <!-- Si no se especifica redondeo,
         se producirá un error de tiempo de ejecución -->
    <Attribute name="roundedDivision">
      <type>
        <javaclass name="Number"/>
      </type>
      <derivation>
        <arithmetic decimalPlaces="3" operation="/"
          rounding="half_up">
          <Number value="2"/>
          <Number value="3"/>
        </arithmetic>
      </derivation>
    </Attribute>

  </Class>

</RuleSet>