version 1 by Jeremy John Reeder

  • Home page
  • Beginning
  • Previous
  • Next

  • Section: Arithmetic
    Inform 7 already provides the syntax "increase/decrease N by (some number)". We add similar phrases for the two remaining standard operations:
        multiply N by (some number)
        divide N by (some number)
    Note that these two phrases can only be used on local variables.
    Next, we have a couple of phrases that deal with the magnitude and sign of numbers:
        the negative of (some number)
        the absolute value of (some number)
        the sign of (some number)
        the difference between (some value) and (some other value)
    The first phrase switches the sign of a number, so that 5 becomes -5 and vice versa. The second just removes the negative sign, so that both 6 and -6 become 6. The third returns -1, 1 or 0 depending on whether the number is negative, positive or zero, and the last phrase (which works with all arithmetic values and not just numbers) simply subtracts the smaller value from the larger.
    Finally, we add an exponentiation operator, using the following syntax:
        (some number) raised to the power of (some other number)