This topic provides a complete overview of type conversion rules for the arithmetic operators.

# The Unary Arithmetic Operators

The unary arithmetic operators in C/AL are so-called prefix operators, whose syntax is:

Copy Code | |
---|---|

PrefixExpression = PrefixOperator Expression |

The following table shows the data types for which the unary operators in C/AL are defined, and the resulting data types.

Unary operator | Option | Integer | Decimal |
---|---|---|---|

+ |
integer |
integer |
decimal |

- |
integer |
integer |
decimal |

# The Binary Arithmetic Operators

The following table shows the data types for which the binary arithmetic operators are defined. The binary arithmetic operators in C/AL are all infix operators, that is:

Copy Code | |
---|---|

InfixExpression = LeftExpression InfixOperator RightExpression |

Operator | Boolean | Char | Option | Integer | Decimal | Date | Time | Text | Code |
---|---|---|---|---|---|---|---|---|---|

+ |
No |
Yes |
Yes |
Yes |
Yes |
Yes |
Yes |
Yes |
Yes |

- |
No |
Yes |
Yes |
Yes |
Yes |
Yes |
Yes |
No |
No |

* |
No |
Yes |
Yes |
Yes |
Yes |
No |
No |
No |
No |

/ |
No |
Yes |
Yes |
Yes |
Yes |
No |
No |
No |
No |

DIV |
No |
Yes |
Yes |
Yes |
Yes |
No |
No |
No |
No |

MOD |
No |
Yes |
Yes |
Yes |
Yes |
No |
No |
No |
No |

In the table, Yes means that the operator can take at least one operand (left, right, or both) of the given type; No means that the operator cannot be used with the given type.

The following table defines the valid uses of the binary arithmetic operators, and the resulting data types.

### Definition of Type Conversion Rules for the "+" Operator

The "+" operator | Boolean | Char | Option | Integer | Decimal | Date | Time | Text | Code |
---|---|---|---|---|---|---|---|---|---|

Boolean |
|||||||||

char |
integer |
integer (C) |
integer (C) |
decimal (C) |
|||||

option |
integer |
integer (C) |
integer (C) |
decimal (C) |
|||||

integer |
integer (C) |
integer (C) |
integer (C) |
decimal (C) |
|||||

decimal |
decimal (C) |
decimal (C) |
decimal (C) |
decimal (C) |
|||||

date |
date (A) (C) |
date (A) (C) |
date (A) (C) |
date (A) (C) (D) |
|||||

time |
time(B) (C) |
time(B) (C) |
time(B) (C) |
time(B) (C) (D) |
|||||

text |
text |
text |
|||||||

code |
text |
code |

(A) The operation is not defined for the date 0D.

(B) The operation is not defined for the time 0T.

(C) Overflow may occur.

(D) The operation is not defined if the decimal has a fractional part.