Contents > 8 Defining Custom Design Metrics and Rules > 8.5 Expression Terms > 8.5.2 Metric Expressions > 8.5.2.1 Mathematical Operators and Functions

#### 8.5.2.1 Mathematical Operators and Functions

The operators allowed in a metric expression are:
• a+b (a plus b, or, if a is a string, the string concatenation of a and b)
• a-b (a minus b)
• a*b (a multiplied by b)
• a/b (a divided by b)
• a^b (a to the power of b)
• a->b or a in b (the number of times a is contained in (multi-)set b; the alternate notation in can be used to avoid conflicts with the special XML character >, see Section 8.5.5 "Expression Terms and XML")
The operators have the following precedence:
1. ^ and -> (or in)
2. the unary - and +
3. * and /
4. + and -
In addition, a number of math and special purpose functions are available.

Math functions

• ln(x): Returns the natural logarithm of x.
• exp(x): Returns Euler's number e raised to the power of x.
• sqrt(x): Returns the square root of x.
• abs(x): Returns the absolute value of x.
• ceil(x): Returns the smallest integer greater or equal to x.
• floor(x): Returns the largest integer smaller or equal to x.
• round(x): Returns the integer closest to x (round(x)=floor(x+0.5)).
Special purpose functions
• length(s): Returns the length of the string s.
• size(s): Returns the number of elements in set s (respecting cardinality if s is a multiset).
• flatsize(s): Returns the number of different elements in set s. For regular sets, this is the same as size, for multisets, the cardinality of elements is disregarded.
• tolowercase(s): Returns a string with all upper case letters in s changed to lower case.
• parsenumber(s): Returns the numerical value of a string that represents a number, e.g. '3' or '-5.15'. The formatting for number constants applies (see Section 8.5.1.1 "Constants").
• typeof(e): Returns the type of the model element e, as a string.
• qualifiedname(e): Returns the fully qualified name (see Section 4.2.2.1 "Qualified Element Names") of the model element e.
Parentheses can be used as usual to override the default precedence. An example of a valid metric expression is -0.5*NumOps^2+(self->AssocCls+ln(NumOps))*NOC/(1+NOD).