TapHome

Mathematical functions

TapHome script mathematical functions — MIN, MAX, AVG (and STRICT variants), ROUND, ABS, DEWPOINT, POWER, MOD, CEIL, FLOOR, RAND, RANDINT, SIGN, SQRT, LOG, LN.

MIN

The MIN function returns the minimum of the provided numeric values. It accepts between 1 and 100 arguments or a single collection. NaN and NULL values are ignored.

MIN( n1, n2, n3, …)
MIN( collection )

Examples:

MIN(40, 80)  		= 40
MIN(2, 2, 6) 		= 2
MIN(80, NAN)		= 80
MIN(NAN, NAN)		= NaN

VAR data := {10, 20, 30}; MIN(data) 	= 10
MIN({1, 2, 3})							= 1
MIN({1, NaN, 3})						= 1

VAR d1 := DATETIME(2014, 12, 8, 0, 0, 0, 0, DateTimeKind.Utc);
VAR d2 := DATETIME(2015, 12, 8, 0, 0, 0, 0, DateTimeKind.Utc);
MIN(d1, d2)			... Result is d1

MINSTRICT

The MINSTRICT function returns the minimum of the provided numeric values. It accepts between 1 and 100 arguments or a single collection. If any of the provided values is NaN or NULL, the function returns NaN/NULL.

MINSTRICT( n1, n2, n3, …)
MINSTRICT( collection )

Examples:

MINSTRICT(40, 80)  		= 40
MINSTRICT(2, 2, 6) 		= 2
MINSTRICT(80, NAN)		= NaN
MINSTRICT(NAN, NAN)		= NaN

VAR data := {10, 20, 30}; MINSTRICT(data) 	= 10
MINSTRICT({1, 2, 3})						= 1
MINSTRICT({1, NaN, 3})						= NaN

VAR d1 := DATETIME(2014, 12, 8, 0, 0, 0, 0, DateTimeKind.Utc);
VAR d2 := DATETIME(2015, 12, 8, 0, 0, 0, 0, DateTimeKind.Utc);
MINSTRICT(d1, NULL, d2)		... Result is NULL

MAX

The MAX function returns the maximum of the provided numeric values. It accepts between 1 and 100 arguments or a single collection. NaN and NULL values are ignored.

MAX( n1, n2, n3, …)
MAX( collection )

Examples:

MAX(40, 80)  			= 80
MAX(2, 2, 6) 			= 6
MAX(80, NAN)			= 80
MAX(NAN, NAN)			= NaN

VAR data := {10, 20, 30}; MAX(data) = 30
MAX({1, 2, 3})						= 3
MAX({1, NaN, 3})					= 3

VAR d1 := DATETIME(2014, 12, 8, 0, 0, 0, 0, DateTimeKind.Utc);
VAR d2 := DATETIME(2015, 12, 8, 0, 0, 0, 0, DateTimeKind.Utc);
MAX(d1, d2)				... Result is d2

MAXSTRICT

The MAXSTRICT function returns the maximum of the provided numeric values. It accepts between 1 and 100 arguments or a single collection. If any of the provided values is NaN or NULL, the function returns NaN/NULL.

MAXSTRICT( n1, n2, n3, …)
MAXSTRICT( collection )

Examples:

MAXSTRICT(40, 80)  			= 80
MAXSTRICT(2, 2, 6) 			= 6
MAXSTRICT(80, NAN)			= NaN
MAXSTRICT(NAN, NAN)			= NaN

VAR data := {10, 20, 30}; MAXSTRICT(data) 	= 30
MAXSTRICT({1, 2, 3})				= 3
MAXSTRICT({1, NaN, 3})				= NaN

VAR d1 := DATETIME(2014, 12, 8, 0, 0, 0, 0, DateTimeKind.Utc);
VAR d2 := DATETIME(2015, 12, 8, 0, 0, 0, 0, DateTimeKind.Utc);
MAXSTRICT(d1, NULL, d2)		... Result is NULL

AVG

The AVG function calculates the average (mean) of the provided numeric values. It accepts between 1 and 100 arguments or a single collection. NaN values are ignored.

AVG( n1, n2, n3, …)
AVG( collection )

Examples:

AVG(40, 80)  		= 60
AVG(2, 2, 6) 		= 3.3333
AVG(80, NAN)		= 80
AVG(‘a’, ‘c’)		= ‘b’
AVG(NAN, NAN)		= NaN

VAR data := {10, 20, 30}; AVG(data) 	= 20
AVG({1, 2, 3})							= 2
AVG({1, NaN, 3})						= 2

AVGSTRICT

The AVGSTRICT function calculates the average (mean) of the provided numeric values. It accepts between 1 and 100 arguments or a single collection. If any of the provided values is not a number, the function returns NaN.

AVGSTRICT( n1, n2, n3, …)
AVGSTRICT( collection )

Examples:

AVGSTRICT(40, 80)  		= 60
AVGSTRICT(2, 2, 6) 		= 3.3333
AVGSTRICT(80, NAN)		= NaN
AVGSTRICT(NAN, NAN)		= NaN

VAR data := {10, 20, 30}; AVGSTRICT(data) 	= 20
AVGSTRICT({1, 2, 3})						= 2
AVGSTRICT({1, NaN, 3})						= NaN

ROUND

ROUND(value1)    

Returns the rounded value.

Example 1: ROUND(2.01)   (Result is 2)
Example 2: ROUND(2.49)   (Result is 2)
Example 3: ROUND(2.5)   (Result is 3)
Example 4: ROUND(2.99)   (Result is 3)

ABS

The ABS function returns the absolute value (i.e. the modulus) of any supplied number.

ABS(number)

Examples:

ABS(100)  ...   100
ABS(-100)   ...   100

DEWPOINT

DEWPOINT(temperature, relativeHumidity)

Returns the dew point temperature given the current temperature and relative humidity. Dew point is calculated according to this equation.

Example 1: DEWPOINT(20, 0.50) (Result is ~9.26)
Example 2: DEWPOINT(0, 1.00) (Result is 0)

POWER

The POWER function calculates a given number, raised to a supplied power.

POWER(number, power)

Examples:

  • POWER(2,3) … 2^3 = 8
  • POWER(10, -3) … 0,001
  • POWER(25, 0) … 1

MOD

The MOD function returns the remainder of a division between two supplied numbers.

MOD(number, divisor)

Arguments:

  • number - The number to be divided.
  • divisor - The value that the number argument is divided by.

Examples:

  • MOD(6, 4)  … 2
  • MOD(6, 2.5) … 1

CEIL

The CEIL function rounds a supplied number away from zero, to the nearest multiple of a given number.

CEIL(number, significance)

Arguments:

  • number   - The number that is to be rounded.
  • significance (optional) - The multiple of significance that the supplied number should be rounded to. If the significance is not specified, then it is equal to 1. (This should generally have the same arithmetic sign (positive or negative) as the supplied number argument)

Examples:

  • CEIL(22.25,0.1) … 22.3
  • CEIL(22.25,1) … 23
  • CEIL(22.25) … 23
  • CEIL(-22.25,-1) … -23
  • CEIL(-22.25,1) … -22
  • CEIL(-22.25) … -22
  • CEIL(-22.25,-5) … -25

FLOOR

The FLOOR function rounds a supplied number towards zero to the nearest multiple of a specified significance.

FLOOR(number, significance)

Arguments:

  • number - The number that is to be rounded.
  • significance (optional) -The multiple of significance that the supplied number is to be rounded to. If the significance is not specified, then it is equal to 1. (This should generally have the same arithmetic sign (positive or negative) as the supplied number argument)

Examples:

  • FLOOR(22.25,0.1)… 22.2
  • FLOOR(22.25,1) … 22
  • FLOOR(22.25) … 22
  • FLOOR(-22.25,-1) … -22
  • FLOOR(-22.25,1) … -23
  • FLOOR(-22.25) … -23
  • FLOOR(-22.25,-5) … -20

RAND

The Rand function generates a random real number between 0 and 1.

RAND()

Examples:

  • RAND()

RANDINT

The RANDINT function generates a random integer between two supplied integers.

RANDINT(bottom, top)

Examples:

  • RANDINT(1,5)
  • RANDINT(-2,2)

SIGN

The SIGN function returns the arithmetic sign (+1, -1 or 0) of a supplied number. I.e. if the number is positive, the SIGN function returns +1, if the number is negative, the function returns -1 and if the number is 0 (zero), the function returns 0.

SIGN(number)

Examples:

  • SIGN(100) … 1
  • SIGN(0) … 0
  • SIGN(-100) … -1

SQRT

The SQRT function calculates the positive square root of a supplied number.

SQRT(number)

Examples:

  • SQRT(25) … 5

LOG

The LOG function calculates the logarithm of a given number, to a supplied base.

LOG(number, base)

Arguments:

  • number - The positive real number that you want to calculate the logarithm of.
  • base (optional) - An optional argument that specifies the base to which the logarithm should be calculated. If the argument is not specified, then the base argument uses the default value 10.

Examples:

  • LOG(4,0.5) … -2
  • LOG(100) … 2

LN

The LN function calculates the natural logarithm of a given number.

LN(number)

where the number argument is the positive real number that you want to calculate the natural logarithm of.

Examples:

  • LN(100) … 4,60517