NCL Home >
Documentation >
Language

# Algebraic Operators

- | Negation |

* | Multiplication |

% | Modulus |

+ | Addition |

> | Greater than |

< | Less than |

^ | Exponentiation |

/ | Division |

# | Matrix multiplication |

Use *(...)* to circumvent precedence rules.

*+* is an overloaded operator:

x = 5.3 + 7.96or

"ab" + 5.3 ==> "ab5.3"Note that

*-*is used both as negation and minus, but that negation has the highest precedence. That is:

x = - 3^2will yield "x = 9" because the "-" is applied to the "3" first, as in "(-3)^2", and not as "- (3^2)". This is unlike Fortran, in which

x = - 3**2yields "x = -9".

The use of parentheses can change the results:

print(- (3+2)^2) ----> yields 25whereas:

print(- ((3+2)^2)) ----> yields -25Finally, note that if "-" appears between two numbers or variables, then it is treated as "minus" rather than "negation". Hence, the following will give you "x = -9":

x = 0 - 3^2