A collection of arithmetic functions and operations, which other Watch Face Format elements use to resolve real-time attribute values and gyroscopic effects.

Introduced in Wear OS 4.

## Example

An example expression for rotating a value up to 5 degrees in either direction, based on the $ x $-value of the Wear OS device's accelerometer:

```
(5/90)*clamp([ACCELEROMETER_ANGLE_X],0,90) + (-5/90)*clamp([ACCELEROMETER_ANGLE_X],-90,0)
```

...which is equivalent to the following mathematical expression, where $ \theta_x $ represents the accelerometer angle in the $ x $-direction:

## Functions

The Watch Face Format recognizes the following string values as functions:

`round()`

- Converts the input value to a floating-point value, then performs the standard
`round()`

mathematical operation. `floor()`

- Performs the standard
`floor()`

mathematical operation. `ceil()`

- Performs the standard
`ceil()`

mathematical operation. `fract()`

- Returns the fractional part of the input value; that is, the part of the floating-point value that appears to the right of the decimal point.
`sin()`

- Performs the standard
`sin()`

trigonometric operation. `cos()`

- Performs the standard
`cos()`

trigonometric operation. `tan()`

- Performs the standard
`tan()`

trigonometric operation. `asin()`

- Performs the standard
`asin()`

trigonometric operation. The returned value is always in the range $ [-\frac{\pi}{2}, \frac{\pi}{2}] $. `acos()`

- Performs the standard
`acos()`

trigonometric operation. The returned value is always in the range $ [0.0, \pi] $. `atan()`

- Performs the standard
`atan()`

trigonometric operation. The returned value is always in the range $ [-\frac{\pi}{2}, \frac{\pi}{2}] $. `abs()`

- Converts the input value to a floating-point value, then performs the standard
`abs()`

mathematical operation. `clamp(,,)`

- Converts the input values to floating-point values, then performs the
`clamp()`

Jetpack operation to fit the first value in the range defined by the second and third values. `rand(,)`

Generates a random floating-point value that fulfills the following conditions at the same time:

- Greater than or equal to the first value.
- Less than or equal to the second value.

Assumes that the first value is less than or equal to the second value.

`log()`

Performs the standard base-$ e $

`log()`

mathematical operation.`log2()`

Simulates a base-2 logarithm. This value is calculated by dividing the base-10 logarithm (

`log10`

of the input value) by the base-10 logarithm of $ 2 $.`log10()`

Performs the standard base-10

`log10`

mathematical operation.`sqrt()`

Performs the standard

`sqrt()`

mathematical operation.`cbrt()`

Performs the standard

`cbrt()`

mathematical operation.`exp()`

Performs the standard

`exp()`

mathematical operation.`expm1()`

Directly calls the

`expm1()`

mathematical operation if the input value is $ 1 $. For any other input value, simulates the function by performing the standard`exp()`

mathematical operation, then subtracting 1.`deg()`

Performs the standard

`toDegrees()`

mathematical operation. $ \frac{\pi}{2} $ is defined as 90 degrees, and $ \pi $ is defined as 180 degrees.`rad()`

Performs the standard

`toRadians()`

mathematical operation. 90 degrees is defined as $ \frac{\pi}{2} $, and 180 degrees is defined as $ \pi $.`pow(,)`

Performs the standard

`pow()`

mathematical operation. The output value is always a floating-point number.`numberFormat(,)`

Applies the number format in the first value to the second value.

The first value can contain the following characters:

`#`

-- represents a numeric digit.`,`

-- represents a comma separator in large numbers.`.`

-- represents a decimal point.

`icuText()`

Converts the input date format string to a pattern that matches the expected locale format. If the parent

`PartText`

element includes a`Localization`

element, that locale's format is used. Otherwise, uses the Wear OS device's current locale.For example, if the device is being used in the United States, an input value of

`EE, MMM d, yyyy h:mm a`

yields the following output:`Tue, Mar 14, 2023 1:59 PM`

`icuBestText()`

Converts the input date format string to the current time whose pattern matches the expected format. If the parent

`PartText`

element includes a`Localization`

element, that locale's format is used. Otherwise, uses the Wear OS device's current locale.For example, if the device is being used in the United States on March 14, 2023 at 1:59 PM, an input value of

`yyyy MMM d EE a h:mm`

yields the following output:`Tue, Mar 14, 2023, 1:59 PM`

`subText(,,)`

Extracts a substring from the first value. The second value indicates the 0-based index into the first value where the substring should begin. The third value indicates the 0-based index into the first value where substring extraction should stop ("from the second value up to, but not including, the third value").

Examples:

`subText("abc def", 2, 5)`

is`c d`

`subText("abc def", 2, 7)`

is`c def`

`textLength()`

Calculates the length of the input string.

## Operators

The Watch Face Format recognizes the following string values as operators:

`+`

- Unary plus, or addition of multiple values. Supports both integers and floating-point values.
`-`

- Unary minus, or subtraction of multiple values. Supports both integers and floating-point values.
`*`

- Multiplication of multiple integer or floating-point values.
`/`

Division of 2 integer or floating-point values.

If division of 2 integers results in a non-integer value, the decimal part is preserved in the floating-point result. For example, $ \frac{1}{2} = 0.5 $.

In addition, the expression $ \frac{x}{0} $ is evaluated as

`0`

, where $ x $ is any integer.`%`

Modular division of 2 integer or floating-point values.

If both operands are integers, the result is the remainder from dividing the 2 values. For example, $ 19 \bmod 7 = 5 $.

If at least one operand is a floating-point number, the result is a floating-point equivalent of the remainder; for example: $ 19.0 \bmod 7 = 5.0 $.

`~`

Bitwise "not" operator. Several examples:

`~1`

is $ -2 $`~0`

is $ -1 $

`!`

Logical "not" operator, which supports double negatives. Several examples:

- $ !2 $ is
`false`

- $ !!0 $ is
`true`

`|`

Bitwise "or" operator. Supports more than 2 input values. Several examples:

- $ 1 | 0 = 1 $
- $ 1 | 2 | 4 = 7 $

`||`

- Logical "or" operator.
`&`

- Bitwise "and" operator. Supports exactly 2 input values.
`&&`

- Logical "and" operator.
`(`

- Open parenthesis. Used for changing the standard order of operations, where multiplication and division ordinarily take priority over addition and subtraction.
`)`

- Closed parenthesis. Used for changing the standard order of operations, where multiplication and division ordinarily take priority over addition and subtraction.
`<`

- The "less than" comparison operator. When comparing an integer value with its
floating-point equivalent, the result is
`false`

. `<=`

- The "less than or equal to" comparison operator. When comparing an integer
value with its floating-point equivalent, the result is
`true`

. `>`

- The "greater than" comparison operator. When comparing an integer value with
its floating-point equivalent, the result is
`false`

. `>=`

- The "greater than or equal to" comparison operator. When comparing an integer
value with its floating-point equivalent, the result is
`true`

. `?`

and`:`

Provides support for ternary operations. The general format is as follows:

`condition ? value_if_true : value_if_false`

Supports nested ternary operations using parentheses.

`,`

Separates values in functions that take more than 1 argument.

`"`

When placed at the beginning and end of a value, indicates that the Watch Face Format should interpret the value as a string.

`==`

Compare for equality. When comparing an integer value with its floating-point equivalent, the result is

`true`

.`!=`

Compare for inequality. When comparing an integer value with its floating-point equivalent, the result is

`false`

.

## Recommended for you

- Note: link text is displayed when JavaScript is off
- SourceType
- ListConfiguration
- PartText