Nevron .NET Vision
Framework / System Layer / Formula Engine / Functions

In This Topic
    Functions
    In This Topic

    You can use functions in formulas to perform additional tasks. Most functions require a set of input arguments, but all functions evaluate to a single variant value. All functions share the following general syntax:

    FUNCTION(arg1, arg2, ...argN)

    where the following rules apply:

    • FUNCTION - must be a valid function name
    • () - the function name must be followed by an open and close parentheses, even if the function takes no arguments.
    • , - the comma is the only allowed delimiter, which can be used to separate arguments.

    The abstraction for a function is defined by the INFunction interface. By default when an instance of the NFormulaEngine is created it uses the default set of predefined functions, which can be obtained from the DefaultFunctions static field.

    You can override the default functions by setting the CustomFunctions property to an instance of the NFunctionCollection class, which contains your custom functions. A reference to the currently used set of functions can be obtained from the UsedFunctions property. If custom functions are not used it returns the DefaulFunctions.

    Following is a glossary of the currently provided functions:

     Bitwise Functions
    Syntax Description Example
    BITAND(binarynumber1, binarynumber2) Returns a 32-bit variant in which each bit is set to 1 only if the corresponding bit in both binarynumber1 and binarynumber2 is 1. Otherwise, the bit is set to 0.

    BITAND(7,2)
    Returns: 2
    (7 = 0111, 2 = 0010)

    BITNOT(binarynumber) Returns a 32-bit binary number in which each bit is set to 1 only if the corresponding bit in binary number is 0. Otherwise, the bit is set to 0. BITNOT(1)
    Returns: 2 ^ 32 - 1
    BITOR(binarynumber1, binarynumber2) Returns a 32-bit binary number in which each bit is set to 1 if the corresponding bit in either binary number1 or binary number2 is 1. The bit is set to 0 only if the corresponding bit is 0 in both binary number1 and binary number2. BITOR(5,3)
    Returns: 7
    (5 = 0101, 3 = 0011, 7 = 0111)
    BITXOR(binarynumber1, binarynumber2) Returns a 32-bit variant in which each bit is set to 1 if the corresponding bit in either but not both binary number1 and binary number2 is 1. Otherwise, the bit is set to 0. BITXOR(5,3)
    Returns: 6
    (5 = 0101, 3 = 0011, 6 = 0110)
     Logical Functions
    Syntax Description Example
    AND(logicalexpression1, logicalexpression2, ..., logicalexpressionN) Returns TRUE (1) if all of the logical expressions supplied are TRUE. If any of the logical expressions are FALSE or 0, the AND function returns FALSE (0).

    AND(true, false)
    Returns: false

    IF(logicalexpression, valueiftrue, valueiffalse) Returns valueiftrue if logicalexpression is TRUE. Otherwise, it returns valueiffalse. IF(a>b, 2, 10)
    Returns 2 if a > b, otherwise returns 10.
    NOT(logicalexpression) Returns TRUE (1) if logicalexpression is FALSE. Otherwise, it returns FALSE (0).

    NOT(true)
    Returns: false

    OR(logicalexpression1, logicalexpression2, ..., logicalexpressionN) Returns TRUE (1) if any of the logical expressions are TRUE.

    OR(true, false)
    Returns: true

     Mathematical Functions
    Syntax Description Example
    ABS(number) Returns the absolute value of a number.

    ABS(-2.5)
    Returns: 2.5

    CEILING(number, multiple) Rounds a number away from 0 (zero) to the next instance of multiple. If multiple is not specified, the number rounds away from 0 to the next integer.

    CEILING(1.7)
    Returns: 2

    CEILING(1.7, 0.25)
    Returns: 1.75

    FLOOR(number, multiple) Rounds a number toward 0 (zero), to the next integer, or to the next instance of multiple. If multiple is not specified, the number rounds toward 0 to the next integer.

    FLOOR(1.7)
    Returns: 1

    FLOOR(1.7, 0.25)
    Returns: 1.5

    INT(number) Rounds a number down to the next integer.

    INT(1.2)
    Returns: 1

    INT(-1.2)
    Returns: -2

    INTUP(number) Rounds a number up to the next integer.

    INTUP(1.2)
    Returns: 2

    INTUP(-1.2)
    Returns: -1

    LN(number) Returns the natural logarithm of a number. The number must be positive.

    LN(10)
    Returns: 2.3026

    LOG10(number) Returns the base 10 logarithm of a number. The number must be positive

    LOG10(10)
    Returns: 1

    MAGNITUDE(constantA, A, constantB, B) Returns the magnitude of the vector whose rise is A and whose run is B, multiplied by the respective constants constantA and constantB. MAGNITUDE is calculated according to the following formula: SQRT((constantA * A) ^ 2 + (constantB * B) ^ 2)

    MAGNITUDE(1, 3, 1, 4)

    Returns: 5

    MAX(number1, number2, ..., numberN) Returns the largest number from a list. Largest means closest to positive infinity. MAX(1, 3, 2)
    Returns: 3
    MIN(number1, number2, ..., numberN) Returns the smallest number from a list. Smallest means closest to negative infinity. MAX(1, 3, 2)
    Returns: 1
    MODULUS(number, divisor) Returns the remainder (modulus) resulting when a number is divided by a divisor. The result has the same sign as the divisor.

    MODULUS(5, 1.4)
    Returns: 0.8.

    MODULUS(5, -1.4)
    Returns -0.6.

    POW(number, exponent) Returns a number raised to the power of an exponent. POW(10, 2)
    Returns: 100
    ROUND(number, numberofdigits).

    Rounds a number to the precision represented by numberofdigits.
    If numberofdigits is greater than 0, number is rounded by numberofdigits to the right of the decimal.
    If numberofdigits is 0, number is rounded to an integer.
    If numberofdigits is less than 0, number is rounded by numberofdigits to the left of the decimal.

    ROUND(123.654,2)
    Returns: 123.65

    ROUND(123.654,0)
    Returns: 124

    ROUND(123.654,-1)
    Returns: 120

    SIGN(number,fuzz) Returns a value that represents the sign of a number.
    The SIGN function returns 1 if number is positive, 0 if number is zero, or -1 if number is negative. Fuzz (optional) helps avoid floating-point roundoff errors when a calculation is almost zero.

    SIGN(-10)
    Returns: -1.

    SIGN(0)
    Returns: 0

    SQRT(number) Returns the square root of a number.

    SQRT(4)
    Returns: 2

    SUM(number1 ,number2, ..., numberN) Returns the sum of a list of numbers. SUM(1,2,3)
    Returns: 6
    TRUNC(number, numberofdigits) Returns a number truncated to numberofdigits.
    If numberofdigits is greater than 0, number is truncated to numberofdigits to the right of the decimal.
    If numberofdigits is 0, number is truncated to an integer.
    If numberofdigits is less than 0, number is truncated to numberofdigits to the left of the decimal.

    TRUNC(123.654,2)
    Returns: 123.65.

    TRUNC(123.654,0)
    Returns: 123

    TRUNC(123.654,-1)
    Returns: 120

     Text Functions
    Syntax Description Example
    CHAR(number) Returns the character for a number. The resulting string is one character in length. CHAR(9)
    Returns: tab character
    LEN(string) Returns the number of characters in a text string. LEN("Hello World")
    Returns: 11
    LOWER(expression) Returns a string converted to lowercase. LOWER("Hello World")
    Returns: "hello world"
    STRSAME(string1, string2, ignoreCase) Determines whether strings are the same. It returns TRUE if they are the same and FALSE if they aren't. The ignoreCase argument indicates whether to perform case-insensitive comparison (by default it is false).

    STRSAME("Hello", "hello")
    Returns: false

    STRSAME("Hello", "hello", true)
    Returns: true

    TRIM(string) Removes all space from string except for single spaces between words. TRIM(" Hello World ")
    Returns: "Hello World"
    UPPER(expression) Returns a string converted to uppercase. UPPER("Hello World")
    Returns: "HELLO WORLD"

     Trigonometrical Functions
    Syntax Description Example
    ACOS(number) Returns the arccosine of number, for example, the angle (in radians) whose cosine is number.

    ACOS(0)

    Returns: PI/2

    ANG360(angle) Normalizes an angle's range to be [0; 2PI). Angle is specified in radians ANG(1.4 + 2 * PI())
    Returns: 1.4
    ASIN(number) Returns the arcsine of a number, for example, the angle (in radians) whose sine is number.

    ASIN(1)

    Returns: PI/2

    ATAN2(y,x) Returns the angle (in radians) between the vector represented by x, y and the direction of the x-axis.

    ATAN2(1,1)
    Returns: PI/4

    ATAN2(1,SQRT(3))
    Returns: PI/6

    ATAN(number) Returns the arctangent of a number, for example, the angle (in radians) whose tangent is number. The resulting angle is in the range [-PI/2; PI/2]

    ATAN(1)
    Returns: PI/4

    COS(angle) Returns the cosine of an angle (in radians) COS(0)
    Returns: 1
    COSH(angle) Returns the hyperbolic cosine of an angle.

    COSH(PI()/4)

    Returns: 1.3246

    DEG(angle) Converts the value of an angle from radians to degrees.

    DEG(PI()/4)

    Returns: 45

    PI() Returns the mathematical constant pi, which is 3.1415926535898. PI()
    Returns: 3.1415926535898
    RAD(angle) Converts the value of an angle from degrees to radians. RAD(45)
    Returns: PI/4
    SIN(angle) Returns the sine of an angle (in radians) SIN(0)
    Returns: 0
    SINH(angle) Returns the hyperbolic sine of an angle (in radians)

    SINH(PI()/4)
    Returns: 0.8687

    TAN(angle) Returns the tangent of an angle (in radians)

    TAN(PI()/4)

    Returns: 1

    TANH(angle) Returns the hyperbolic tangent of an angle (in radians)

    TANH(-PI()/4)
    Returns: -0.6558

    See Also