# Mathematical Functions

Functions for performing mathematical operations.

## Abs

### Abs( value ) -> `Number`

Returns the absolute value of a number. If the input is `null`, then it returns 0.

Name Type Description
value Number A number on which to perform the operation.

#### Example

prints 3

``Abs(-3)``

## Acos

### Acos( value ) -> `Number`

Returns the arccosine of the input value in radians, in the range of zero to PI. If the input value is outside the appropriate range of +/- 1, then NaN is returned.

Name Type Description
value Number A number between -1 and 1 on which to perform the operation.

#### Example

prints 1.266104

``Acos(0.3)``

## Asin

### Asin( value ) -> `Number`

Returns the arcsine of the input value in radians, in the range of -PI/2 and PI/2. If the input value is outside the appropriate range of +/- 1, then NaN is returned.

Name Type Description
value Number A number between -1 and 1 on which to perform the operation.

#### Example

prints 0.304693

``Asin(0.3)``

## Atan

### Atan( value ) -> `Number`

Returns the arctangent of the input value in radians, in the range of -PI/2 and PI/2.

Name Type Description
value Number A number on which to perform the operation.

#### Example

prints 0.785398

``Atan(1)``

## Atan2

### Atan2( y, x ) -> `Number`

Returns the arctangent of the quotient of the input values in radians, in the range of -PI and zero or zero and PI depending on the sign of arguments.

Name Type Description
y Number A number representing the y-coordinate.
x Number A number representing the x-coordinate.

#### Example

prints -2.356194

``Atan2(-1, -1)``

## Average

### Average( values, fieldName? ) -> `Number`

Returns the average of a set of numbers. In profiles that support accessing data, this function can return the average value of a given numeric field in a FeatureSet.

Name Type Description
values Number[] | FeatureSet A list or array of numbers on which to perform the operation. In profiles that support accessing data, this can be a FeatureSet.
fieldName Text `optional` Specifies the name of a numeric field or SQL92 expression for which the statistic will be calculated from the input FeatureSet. This parameter only applies when a FeatureSet is specified.

#### Example

prints 5

``````var values = [0,5,10]
Average(values)``````

calculates the difference between the feature's population and the average population of all features in the layer

``\$feature.population - Average(\$layer, 'population')``

calculates the average population per square mile of all features in the layer

``Average(\$layer, 'population / area')``

## Ceil

### Ceil( value, numPlaces? ) -> `Number`

Returns the input value rounded upwards to the given number of decimal places.

Name Type Description
value Number The number to round upward.
numPlaces Number `optional` The number of decimal places to round the `value` to. Default is 0. Trailing zeros will be truncated.

#### Example

prints 2135.1

``Ceil(2135.0905, 2)``

## Constrain

### Constrain( value, min, max ) -> `Number`

Since version 1.2

Constrains the given input `value` to minimum and maximum bounds. For example, if the input value is `10`, the lower bound is `50`, and the upper bound is `100`, then `50` is returned.

Name Type Description
value Number The value to constrain to the given `min` and `max` bounds.
min Number The lower bound by which to constrain the input `value`. If the given value is less than the `min`, then `min` is returned.
max Number The upper bound by which to constrain the input `value`. If the given value is greater than the `max`, then `max` is returned.

#### Example

returns 5

``Constrain(5, 0, 10)``

returns 0

``Constrain(-3, 0, 10)``

returns 10

``Constrain(553, 0, 10)``

## Cos

### Cos( value ) -> `Number`

Returns the cosine of the input value in radians.

Name Type Description
value Number A number in radians on which to perform the operation.

#### Example

prints 0.540302

``Cos(1)``

## Exp

### Exp( x ) -> `Number`

Returns the value of e to the power of x, where e is the base of the natural logarithm `2.718281828`.

Name Type Description
x Number The power, or number of times to multiply `e` to itself.

#### Example

prints 7.389056

``Exp(2)``

## Floor

### Floor( value, numPlaces? ) -> `Number`

Returns the input value rounded downward to the given number of decimal places.

Name Type Description
value Number A number to round downward.
numPlaces Number `optional` The number of decimal places to round the number. Default is 0. Trailing zeros will be truncated.

#### Example

prints 2316.25

``Floor(2316.2562, 2)``

## Log

### Log( x ) -> `Number`

Returns the natural logarithm (base e) of x.

Name Type Description
x Number A number on which to perform the operation.

#### Example

prints 2.302585

``Log(10)``

## Max

### Max( values, fieldName? ) -> `Number`

Returns the highest value from an array of numbers. In profiles that support accessing data, this function can return the highest value for a given numeric field from a FeatureSet.

Name Type Description
values Number[] | FeatureSet An array or list of numbers. In profiles that support accessing data, this can be a FeatureSet.
fieldName Text `optional` Specifies the name of a numeric field or SQL92 expression for which the statistic will be calculated from the input FeatureSet. This parameter only applies when a FeatureSet is specified.

#### Example

prints 89

``Max([23,56,89])``

prints 120

``Max(23,5,120,43,9)``

prints the max value of the population field for all features in the layer

``Max(\$layer, 'population')``

calculates the max population per square mile of all features in the layer

``Max(\$layer, 'population / area')``

## Mean

### Mean( values, fieldName? ) -> `Number`

Since version 1.1

Returns the mean value of an array of numbers. In profiles that support accessing data, this function can return the mean value of a given numeric field in a FeatureSet.

Name Type Description
values Number[] | FeatureSet A list or array of numbers from which to calculate the mean. In profiles that support accessing data, this can be a FeatureSet.
fieldName Text `optional` Specifies the name of a numeric field or SQL92 expression for which the statistic will be calculated from the input FeatureSet. This parameter only applies when a FeatureSet is specified.

#### Example

###### Use a single array as input

returns 5

``````var values = [1,2,3,4,5,6,7,8,9];
Mean(values);``````
###### Use comma separated values with array element

returns 5

``````var values = [0,10];
Mean(0,10,5,values);``````

calculates the difference between the feature's population and the mean population of all features in the layer

``\$feature.population - Mean(\$layer, 'population')``

calculates the mean population per square mile of all features in the layer

``Mean(\$layer, 'population / area')``

## Min

### Min( values, fieldName? ) -> `Number`

Returns the lowest value in a given array. In profiles that support accessing data, this function can return the lowest value for a given numeric field from a FeatureSet.

Name Type Description
values Number[] | FeatureSet An array or list of numbers. In profiles that support accessing data, this can be a FeatureSet.
fieldName Text `optional` Specifies the name of a numeric field or SQL92 expression for which the statistic will be calculated from the input FeatureSet. This parameter only applies when a FeatureSet is specified.

#### Example

prints 23

``Min([23,56,89])``

prints 5

``Min(23,5,120,43,9)``

prints the min value of the population field for all features in the layer

``Min(\$layer, 'population')``

returns the minimum population per square mile of all features in the layer

``Min(\$layer, 'population / area')``

## Pow

### Pow( x, y ) -> `Number`

Returns the value of x to the power of y.

Name Type Description
x Number The base value.
y Number The exponent. This indicates the number of times to multiply `x` by itself.

#### Example

prints 9

``Pow(3, 2)``

## Random

### Random( ) -> `Number`

Returns a random number between 0 and 1.

Name Type Description

#### Example

``Random()``

## Round

### Round( value, numPlaces? ) -> `Number`

Returns the input value, rounded to the given number of decimal places.
Note: If you're looking to format a value for display in a label or popup, use the [text](../datafunctions/#text) function._

Name Type Description
value Number A number to round.
numPlaces Number `optional` The number of decimal places to round the number to. Default is `0`. Trailing zeros will be truncated.

#### Example

prints 2316.26

``Round(2316.2562, 2)``

## Sin

### Sin( value ) -> `Number`

Returns the sine of the input value.

Name Type Description
value Number A number in radians on which to perform the operation.

#### Example

prints 0.841741

``Sin(1)``

## Sqrt

### Sqrt( value ) -> `Number`

Returns the square root of a number.

Name Type Description
value Number A number on which to calculate the square root.

#### Example

prints 3

``Sqrt(9)``

## Stdev

### Stdev( values, fieldName? ) -> `Number`

Returns the standard deviation (population standard deviation) of a set of numbers. In profiles that support accessing data, this function can return the standard deviation for the values from a given numeric field in a FeatureSet.

Name Type Description
values Number[] | FeatureSet An array or list of numbers on which to perform the operation. In profiles that support accessing data, this can be a FeatureSet.
fieldName Text `optional` Specifies the name of a numeric field or SQL92 expression for which the statistic will be calculated from the input FeatureSet. This parameter only applies when a FeatureSet is specified.

#### Example

prints 27.5

``Stdev(23,56,89,12,45,78)``

prints the standard deviation of values from the 'population' field

``Stdev(\$layer, 'population')``

calculates the standard deviation of the population per square mile of all features in the layer

``Stdev(\$layer, 'population / area')``

## Sum

### Sum( values, fieldName? ) -> `Number`

Returns the sum of a set of numbers. In profiles that support accessing data, this function can return the sum of values returned from a given numeric field in a FeatureSet.

Name Type Description
values Number[] | FeatureSet An array of numbers on which to perform the operation. In profiles that support accessing data, this can be a FeatureSet.
fieldName Text `optional` Specifies the name of a numeric field or SQL92 expression for which the statistic will be calculated from the input FeatureSet. This parameter only applies when a FeatureSet is specified.

#### Example

prints 303

``Sum(23,56,89,12,45,78)``

calculates the population of the current feature as a % of the total population of all features in the layer

``( \$feature.population / Sum(\$layer, 'population') ) * 100``

calculates the total number of votes cast in an election for the entire dataset

``Sum(\$layer, 'democrat + republican + other')``

## Tan

### Tan( value ) -> `Number`

Returns the tangent of an angle in radians.

Name Type Description
value Number A number on which to calculate the tangent.

#### Example

prints 0.57389

``Tan(0.521)``

## Variance

### Variance( values, fieldName? ) -> `Number`

Returns the variance (population variance) of a set of numbers. In profiles that support accessing data, this function can return the variance of the values from a given numeric field in a FeatureSet.

Name Type Description
values Number[] | FeatureSet An array of numbers on which to perform the operation. In profiles that support accessing data, this can be a FeatureSet.
fieldName Text `optional` Specifies the name of a numeric field or SQL92 expression for which the statistic will be calculated from the input FeatureSet. This parameter only applies when a FeatureSet is specified.

#### Example

prints 756.25

``Variance(12,23,45,56,78,89)``

prints the variance for the population field in the given layer

``Variance(\$layer, 'population')``

calculates the variance of the population per square mile of all features in the layer

``Variance(\$layer, 'population / area')``