CDL Functions

In addition to operators, expressions can contain functions, which may take arguments and return results that can be used in the rest of the expression. All standard mathematical functions are implemented in CDL.

The result of each function can participate as an operand of another operator or function as long as the return type of the former matches with the argument type of the latter.

Functions perform operations on their arguments and return values which are used in evaluating the entire statement. Functions must have their arguments enclosed in parentheses and separated by commas if there is more than one argument. Function arguments can be expressions.

For example, both of the following operations have the correct syntax for the Round function, provided that Feature-1 and Feature-2 are numeric Features:

Round (13.4)
Round (Feature-1 / Feature-2)

CDL supports the following functions:

  • Arithmetic

  • Trigonometric

  • Logical

  • Set

  • Text

  • Hierarchy or Compound

Arithmetic Functions

The following table lists the arithmetic functions that are available in CDL. The term infinity is defined as a number without bounds. It can be either positive or negative.

Function

Description

Abs(x)

Takes a single number as an argument and returns the positive value (0 to +infinity). The domain range is -infinity to +infinity. Returns the positive value of x. Abs(-12345.6) results in 12345.6

AggregateSum(x)

Can be used in a Constraint, Default, or Search Decision, but only as a sub-expression.

Round(x)

Takes a single decimal number as an argument and returns the nearest integer. If the A side of a numeric rule is a decimal number, contributing to an imported bill of materials that accepts decimal quantities, then the Round(x) function is unavailable. The reason that the Round(x) function is unavailable is that the contributed value doesn't need to be rounded as the B side accepts decimal quantities. This function is available when the bill of materials item accepts only integer values.

RoundDownToNearest(x,y)

This is a binary function. x is a number between -infinity and +infinity, y is a number greater than 0 and less than +infinity. A number is returned between -infinity and +infinity. The first argument is rounded to the nearest smaller multiple of the second argument. For example, RoundDownToNearest(433,75) returns 375.

RoundToNearest(x,y)

This is a binary function. x is a number between -infinity and +infinity, y is a number greater than 0 and less than +infinity. A number is returned between -infinity and +infinity. RoundToNearest(433,10) returns 430.

RoundUpToNearest(x,y)

This is a binary function. The number x is between -infinity and +infinity, and the number y is greater than 0 and less than +infinity. A number is returned between -infinity and +infinity. The first argument is rounded up to the nearest multiple of the second argument. For example, RoundUpToNearest(34.1,0.125) returns 34.125.

Ceiling(x)

Takes a single decimal number as an argument and returns the next higher integer. For example, ceiling(4.3) returns 5, and ceiling(-4.3) returns -4.

Floor(x)

Takes a single decimal number as an argument and returns the next lower integer. For example, floor(4.3) returns 4, and floor(-4.3) returns -5.

Log(x)

Takes a single number greater than 0 and less than +infinity and returns a number between -infinity and +infinity. Returns the logarithmic value of x. An error happens if x=0.

Log10(x)

Takes a single number greater than 0 and less than +infinity and returns a number between -infinity and +infinity. Returns the base 10 logarithm of x. An error happens if x=0.

Min(x,y,z...)

Returns the smallest of its numeric arguments.

Max(x,y,z...)

Returns the largest of its numeric arguments.

Mod(x,y)

This is a binary function. Returns the remainder of x/y where x and y are numbers between -infinity and +infinity. If y is 0, then division by 0 is treated as an error. If x=y, then the result is 0. For example, Mod(7,5) returns 2.

Exp(x)

Returns e raised to the x power. Takes a single number between -infinity and +infinity and returns a value between 0 and +infinity.

Pow(x,y)

This is a binary function. Returns the result of x raised to the power of y. The number x is between -infinity and +infinity. The integer y is between -infinity and +infinity and the returned result is between -infinity and +infinity. If y=0, then the result is 1. For example, Pow(6,2) returns 36.

Sqrt(x)

Sqrt(x) returns the square root of x. Takes a single number between 0 and +infinity and returns a value between 0 and +infinity. An input of -x results in an error.

Truncate(x)

Truncate(x) takes a single decimal number x and truncates it, removing all digits after the decimal point. For example, truncate(4.15678) returns 4.

Trigonometric Functions

The following table lists the trigonometric functions that are available in CDL.

Function

Description

Sin(x)

Takes a single number x between -infinity and +infinity and returns a value between -1 and +1.

ASin(x)

Takes a single number between -1 and +1 and returns a value between -pi/2 and +pi/2. ASin(x) returns the arc sine of x. An input outside the range between -1 and +1 results in an error.

Sinh(x)

Returns the hyperbolic sine of x in radians. Takes a single number between -infinity and +infinity and returns a value between -1 and +infinity. An error is returned when the result exceeds the double. For example, sinh(-99) is valid but sinh(999) results in an error.

Cos(x)

Takes a single number between -infinity and +infinity and returns a value between -1 and +1. Returns the cosine of x.

ACos(x)

Takes a single number between -1 and +1 and returns a value between 0 and pi. ACos(x) returns the arc cosine of x. An input outside the range between -1 and +1 results in an error.

Cosh(x)

Takes a single number between -infinity and +infinity and returns a value between -infinity and +infinity. Returns the hyperbolic cosine of x in radians. An error is returned if x exceeds the maximum value of a double: cosh(-200) is valid whereas cosh(-2000) results in an error.

Tan(x)

Takes a single number x between -infinity and +infinity and returns a value between -infinity and +infinity.

ATan(x)

Takes a single number between -infinity and +infinity and returns a value between -pi/2 and +pi/2. ATan(x) returns the arc tangent of x.

Tanh(x)

Returns the hyperbolic tangent of x. Takes a single number x between -infinity and +infinity and returns a value between -1 and +1.

Logical Functions

The following table lists the logical functions that are available in CDL.

Function

Description

AllTrue

A logical AND expression. Accepts one or more logical values or expressions. Returns true if all of the arguments are true, or false if any argument is false. Otherwise, the value of AllTrue is unknown.

AnyTrue

A logical OR expression. Accepts one or more logical values or expressions. Returns true if any of the arguments are true, or false if all arguments are false. Otherwise, the value of AnyTrue is unknown.

Not

Accepts a single logical value or expression. Returns True if the argument is False or unknown. If the argument is True, the value is unknown.

Text Functions

The following table lists the text functions that are available in CDL.

Note: As with any TEXT data type, don't use a text function in the body of a CONSTRAIN or accumulator statement unless it evaluates to a constant string. The compiler validates this condition.

Text functions can only be used in static context; for example the WHERE clause of iterators.

Function

Description

Contains

Compares two operands of text literals and returns true if the first contains the second.

Matches

Compares two operands of text literals and returns true if they match.

BeginsWith

Compares two operands of text literals and returns true if the first begins with the characters of the second.

EndsWith

Compares two operands of text literals and returns true if the first ends with the character(s) of the second.

Equals

Compares two operands of text literals and returns true if the first equals the second.

NotEquals

Compares two operands of text literals and returns true if the first doesn't equal the second

Hierarchy or Compound Functions

The following table lists the compound function that's available in CDL.

Function

Description

OptionsOf

Takes Option Class or Feature as an argument and returns its Options.