# Operators

Operators are special symbols or keywords that take a left and right operand, returning some sort of result.

The following operators are supported by the FHIRPath implementation within Pathling:

• Equality (`=` and `!=`)
• Comparison (`<=`, `<`, `>` and `>=`)
• Math (`+`, `-`, `*`, `/` and `mod`)
• Boolean logic (`and`, `or`, `xor` and `implies`)
• Membership (`in` and `contains`)

## Equality

The `=` operator returns `true` if the left operand is equal to the right operand, and a `false` otherwise. The `!=` is the inverse of the `=` operator.

The equality operators can accept operands of type String, Integer, Decimal, Boolean, Date and DateTime.

Both operands must be of the same type, and must be singular.

If one or both of the operands is an empty collection, the operator will return an empty collection.

## Comparison

The following comparison operators are supported:

• `<=` - Less than or equal to
• `<` - Less than
• `>` - Greater than
• `>=` - Greater than or equal to

The comparison operators can accept operands of type String, Integer, Decimal, Date and DateTime.

Both operands must be of the same type, and must be singular.

If one or both of the operands is an empty collection, the operator will return an empty collection.

String ordering is strictly lexical and is based on the Unicode value of the individual characters.

All comparison operators return a Boolean value.

## Math

The following math operators are supported:

• `+` - Addition
• `-` - Subtraction
• `*` - Multiplication
• `/` - Division
• `mod` - Modulus

Math operators support only Integer and Decimal operands.

The type of the two operands can be mixed. `+`, `-` and `*` return the same type as the left operand, `/` returns Decimal and `mod` returns Integer.

Both operands must be of the same type, and must be singular.

If one or both of the operands is an empty collection, the operator will return an empty collection.

## Boolean logic

The following Boolean operations are supported:

• `and`
• `or`
• `xor` - Exclusive OR
• `implies` - Material implication

Both operands to a Boolean operator must be singular Boolean values.

All Boolean operators return a Boolean value.

## Membership

The following membership operators are supported:

• `in`
• `contains`

If the left operand is a collection with a single item, the `in` operator returns `true` if the item is in the right operand using equality semantics.

If the left-hand side of the operator is empty, the result is empty. If the right-hand side is empty, the result is `false`. If the left operand has multiple items, an error is returned.

The `contains` operator is the inverse of `in`.