Declarative Objectivity (DO) Language : Operator Expressions : Arithmetic Operators
Arithmetic Operators
Arithmetic operators produce values as the result of arithmetic calculations on numeric or date-time operands.
 Operator Description Usage First Operand (op1) Second Operand(op2) Result Type1 + Unary plus +op1 Numeric — Numeric - Unary minus -op1 Numeric — Numeric *MULTIPLY Multiplication op1 * op2op1 MULTIPLY op2MULTIPLY(op1, op2) Numeric Numeric Numeric /DIVIDE Division op1 / op2op1 DIVIDE op2DIVIDE(op1, op2) Numeric Numeric Numeric %MODULO Modulus (remainder) op1 % op2op1 MODULO op2MODULO(op1, op2) Integer Integer Integer +PLUS Addition op1 + op2op1 PLUS op2PLUS(op1, op2) Numeric Numeric Numeric Date, Time, DateTime, Interval Interval Same as op1 -MINUS Subtraction op1 - op2op1 MINUS op2MINUS(op1, op2) Numeric Numeric Numeric Date, Time, DateTime, Interval Interval Same as op1 Date, Time, DateTime Same as op1 Interval IS_NAN Checks for an undefined number; returns true if found. IS_NAN(op1) Real (floating-point) number — Boolean IS_INF Checks for an infinite number; returns true if found. IS_INF(op1) Real (floating-point) number — Boolean 1. The arithmetic operators return null if either operand is a null value.
Quick Look
Update the luxury vehicle category by changing its rate to \$20 less than double the current rate:
`UPDATE VehicleCategory WHERE name == 'Luxury' SET rate TO rate * 2 - 20 RETURN rate;`
Return the interval (number of days, hours, minutes, etc.) between a particular reservation’s timestamp and the given datetime (March 30, 2017 at 12:00 a.m. UTC):
`FROM Reservation WHERE \$\$ID == 3-3-2-82 RETURN timestamp - 2017-3-30 00:00:00Z;`
Return the date and time that is 5 days and 8 hours earlier than a particular reservation’s timestamp:
`FROM Reservation WHERE \$\$ID == 3-3-2-82 RETURN timestamp - INTERVAL{days:5, hours:8};`
Operator expression that evaluates to true if the value of the real (floating-point) attribute myFloat is not a number:
`IS_NAN(myFloat)`
Discussion
For general information about operator formats, operands, and precedence, see About Operator Expressions.
When performing arithmetic operations on datetimes, the two datetime values may be expressed in different time zones; the operator automatically converts them to the same time zone.
Implicit Type Coercion of Numeric Operands
For numeric arithmetic operators, implicit type coercion is performed on the operands. In a mixed-type numeric expression, the following precedence of data types is used (lowest to highest): The value of the operand of the lower type is promoted to that of the higher type and the result is an expression of the higher type. For example, an integer multiplied by a floating-point number returns a floating-point number.
Arithmetic Operations on Dates, Times, and Datetimes
You can use the PLUS operator to return a date, time, or datetime that is later by an amount of time expressed as an interval. Similarly, you can use the MINUS operator to return a date, time, or datetime that is later by an amount of time expressed as an interval.
Example. The following statement returns the date and time that is 5 days and 8 hours later than a particular reservation’s timestamp:
`FROM Reservation WHERE \$\$ID == 3-3-2-82 RETURN timestamp + INTERVAL{days:5, hours:8};`
You can use the MINUS operator to return the amount of time (expressed as an interval) between two dates, two times, or two datetimes. If the two operands are datetime values that are expressed in different time zones, they are automatically converted to the same time zone before the subtraction is performed.
Example. The following statement returns the interval (number of days, hours, minutes, etc.) between a particular reservation’s timestamp and the given datetime (March 30, 2017 at 12:00 a.m. UTC). If the value of timestamp is expressed in the local time standard, that value is implicitly converted to the UTC time standard before the difference is computed:
`FROM Reservation WHERE \$\$ID == 3-3-2-82 RETURN timestamp - 2017-3-30 00:00:00Z;`