- (minus)


Return type:
The difference between its two operands (binary form), or the operand * -1 (unary form).
numeric-expression  -  numeric-expression


- numeric-expression


You can subtract one numeric value from another using -, the minus operator. To subtract BCD numbers, you must import the ombcd.xmd file in your program. To subtract floating point numbers, import the omfloat.xmd file.

You can subtract values of mixed data types (for example, BCD numbers and integers) as long as you follow the rules listed in Operations with mixed data types.

You can also use - as a unary operator (an operator with only one argument) to reverse the sign of a numeric expression.

Always surround arithmetic operators with spaces.

BCD Example:

  ; Profit = Revenue - Expenses - Tax
    import "ombcd.xmd" unprefixed
        local bcd revenue-total initial {99295.21}
        local bcd expense-total initial {56932.98}
        local bcd tax-total initial {22345.67}
        local bcd profit 
        set profit to revenue-total - expense-total - tax-total
        output "Profit is " 
            || "<$,NNZ.ZZ>" % profit  
            || "%n"
        ; Output: 'Profit is $20,016.56'.

Floating Point Example:

  ; Find the difference between the radius of the earth and that of the moon.
    import "omfloat.xmd" unprefixed
        local float earth-radius initial {6.371 * float 10 ** 106}
        local float moon-radius initial {1.7383 * float 10 ** 106}
        local float radius-difference
        set radius-difference to earth-radius  - moon-radius
        output "The difference between the radius of the earth and the moon is " 
            || "10fed" % radius-difference  || " meters.%n"
  ; Output: 'The difference between the radius of the earth and the moon is 4.6327e+106 meters.

Mixed Data Type Example:

  ; Distance from destination = (Total distance) - (Mileposts passed)
    import "ombcd.xmd" unprefixed
        local bcd total-distance initial {464.21}
        local bcd distance-from-destination
        local integer mileposts-passed initial {219}
        set distance-from-destination to total-distance - mileposts-passed
        output "Distance from destination is " 
            || "d" % distance-from-destination
            || "miles.%n"
        ; Output: 'Distance from destination is 245.21 miles'.

The word minus is a deprecated synonym for -.

For floating point numbers, overflow and underflow values return infinity and zero, respectively.

BCD numbers cannot overflow, but underflow returns 0.

For integers, underflow returns zero, but overflow returns an incorrect answer that depends on the operating system.

Related Concepts