# Arithmetic Operators

Arithmetic operations perform the basic mathematical operations of addition, subtraction, multiplication, division, and modulo within an expression or any numerical value retrieved as part of query clauses. Additionally, N1QL provides a negation operation which changes the sign of a value.

 These arithmetic operators only operate on numbers. In N1QL, arithmetic operators have their usual meaning. However, in any of these expressions: If any operand is MISSING, the value of the expression is MISSING. If any operand is NULL and no operand is MISSING, the value of the expression is NULL. If any operand is not a number, the operator evaluates to NULL.
Operator Description

+

-

Subtract right value from left value.

*

Multiply values.

/

Divide left value by right value.

%

Modulo. Divide left value by right value and return the remainder.

NOTE: Modulo is an integer operator and will use only the integer part of each value.

-`value`

Negate value.

## Syntax

There are six different arithmetic syntaxes:

```expr1 + expr2

expr1 - expr2

expr1 * expr2

expr1 / expr2

expr1 % expr2

-expr1```

## Arguments

expr1, expr2

Number or an expression that results in a number value.

Return Values

A number, representing the value of the arithmetic operation.

## Examples

Example 1: Select the longest flight and return its two airports and the distance in feet.

```SELECT sourceairport, destinationairport, ROUND(distance) AS DistanceInMiles,
ROUND(distance)*5280 AS DistanceInFeet
FROM `travel-sample`
WHERE type="route"
ORDER BY distance DESC
LIMIT 1;

Returns:
[
{
"DistanceInFeet": 72906240,
"DistanceInMiles": 13808,
"destinationairport": "DFW",
"sourceairport": "SYD"
}
]```

Example 2: Select the modulo of 5 and 3 and compare to the modulo of 5.4 and 3.4.

```SELECT 5 % 3;

Returns:
[
{
"\$1": 2
}
]

SELECT 5.4 % 3.4;

Returns:
[
{
"\$1": 2
}
]```
{"ft_lang_label":"__label__en","ft_lang_prob":0.70049286,"math_prob":0.98330414,"size":1654,"snap":"2019-13-2019-22","text_gpt3_token_len":418,"char_repetition_ratio":0.1430303,"word_repetition_ratio":0.03018868,"special_character_ratio":0.26904473,"punctuation_ratio":0.18055555,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.99166065,"pos_list":[0],"im_url_duplicate_count":[null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2019-03-20T04:46:46Z\",\"WARC-Record-ID\":\"<urn:uuid:6382cab8-ac51-4f17-8e0c-a6efc8e2b803>\",\"Content-Length\":\"137203\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:bf31b24e-f930-4c1a-9524-0ce485fdfb14>\",\"WARC-Concurrent-To\":\"<urn:uuid:b8647136-b699-4686-a864-754be6a74b87>\",\"WARC-IP-Address\":\"13.249.44.119\",\"WARC-Target-URI\":\"https://docs.couchbase.com/server/6.0/n1ql/n1ql-language-reference/arithmetic.html\",\"WARC-Payload-Digest\":\"sha1:CNM6FEHL5WWEMZRSS3PYDFNCRULAVIKO\",\"WARC-Block-Digest\":\"sha1:NXVHWEVDM26XZPOALAN7PWKZ2E5547AB\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2019/CC-MAIN-2019-13/CC-MAIN-2019-13_segments_1552912202299.16_warc_CC-MAIN-20190320044358-20190320070358-00231.warc.gz\"}"}