# Formulas

There are many situations where formulas can be used in Rainmeter to arrive at a numerical result. These might be things like:

- In a Calc measure:
`Formula=(2.5 + 100) * 2`

- In an IFCondition option value:
`IfCondition=MeasureName > (2.5 + 100) * 2`

- In a numeric meter or measure option value:
`W=((2.5 + 100) * 2)`

- As a numeric part of an option value:
`FontColor=(255 * 0.5),255,255,255`

- In a Bang:
`LeftMouseUpAction=[!SetOption SomeMeter W "((2.5 + 100) * 2)"]`

There are a few place where formulas are not allowed. These are primarily places where the option value is assumed to be a string and only a string. In those cases, the characters used in a formula are treated as any other string character. A few examples are:

- The
`Text`

option of a String meter. - The
`String`

option of a String measure. - The
`RegExp`

option of a WebParser measure. `IfMatch`

options.`TootipText`

or`TooltipTitle`

options.

While formulas can be used in the [Variables] section of a skin, be aware that the [Variables] section itself does not resolve the formula. If you have a variable `MyVar=(5 * 2)`

, then the value of #MyVar# is not "10", but literally "(5 * 2)". However, if you then use the variable in an option that does allow formulas, that option itself will do the math, as in `X=#MyVar#`

in a meter.

Mathematical formulas must be entirely enclosed in (parentheses) to alert Rainmeter that it is a formula, unless they are being used in the Formula option of a Calc measure or in a IfCondition option, where the function is always assumed to be a formula, and the enclosing parentheses are optional.

**Note:** While [Measures], [SectionVariables:] and #Variables# can be used in a formula, all the components of a formula must be numeric, using only numbers, operators, functions and constants. Using .5 or .25 in a formula will cause an error. It must be 0.5 or 0.25.

## Formula Syntax

### Operators

`+`

: Addition`-`

: Subtraction`*`

: Multiplication`/`

: Division`**`

: Power`%`

: Remainder or modulus`&`

: Bitwise and`|`

: Bitwise or`^`

: Bitwise xor`~`

: Bitwise not

### Logical Operators

`<>`

: Not equal`=`

: Equal to`>`

: Greater than`<`

: Less than`<=`

: Less than or equal to`>=`

: Greater than or equal to`&&`

: Logical and`||`

: Logical or

**Note:** Conditional statements using logical operators evaluate to 1 or 0 (true / false).

### Functions

`Cos(`

: The cosine of an angle of*x*)*x*radians.`Sin(`

: The sine of an angle of*x*)*x*radians.`Tan(`

: The tangent of an angle of*x*)*x*radians.`Acos(`

: The principal arc cosine of*x*)*x*, in the interval [0,PI] radians. The value of*x*is between -1 and 1.`Asin(`

: The principal arc sine of*x*)*x*, in the interval [-PI/2,+PI/2] radians. The value of*x*is between -1 and 1.`Atan(`

: The principal arc tangent of x, in the interval [-PI/2,+PI/2] radians.*x*)`Atan2(`

: The principal arc tangent in the interval [-PI,+PI] radians between points*y*,*x*)*y*and*x*in the Cartesian plane. The sign of the elements determines the quadrant.`Rad(`

: Converts*x*)*x*degrees to radians.`Deg(`

: Converts*x*)*x*radians to degrees.`Abs(`

: Absolute value of*x*)*x*.`Neg(`

: Negative value of*x*)*x*.`Exp(`

: Returns*x*)*e*^{x}.`Log(`

: Base 10 logarithm of*x*)*x*.`Ln(`

: Natural logarithm of*x*)*x*.`Sqrt(`

: Square root of*x*)*x*.`Sgn(`

: Return 1 if x is positive, -1 if x is negative, or 0 if x is zero.*x*)`Frac(`

: Fractional, or decimal, part of*x*)*x*. (e.g. frac(1.234) = 0.234)`Trunc(`

: Integer part of*x*)*x*. (e.g. trunc(1.234) = 1)`Floor(`

: Floor of*x*)*x*.`Ceil(`

: Ceiling of*x*)*x*.`Min(`

: Minimum of*x*,*y*)*x*and*y*.`Max(`

: Maximum of*x*,*y*)*x*and*y*.`Clamp(`

: Restricts value*x*,*low*,*high*)*x*to*low*and*high*limits.`Round(`

: Rounds*x*,*precision*)*x*to an integer, or to a specified number of decimal places.*precision*is optional.

### Constants

`PI`

: Mathematical constant Pi (~3.14159265...).`E`

: Mathematical constant e (~2.71828182...).

### Conditional Operations

`<condition> ? <expr. if true.> : <expr. if false.>`

This will evaluate condition as being either true or false. If it is true, the expression to the left of the colon (:) is evaluated. If it is false, the expression to the right is evaluated. This is equivalent to the following if-then-else statement:

if (condition) |

[Measure] |

The meter would be positioned at `X=0`

since the condition `[Measure] < 6`

evaluates to true.

Conditional operators can be nested. It should be noted that there is a maximum of 30 nested operators.

[Measure] |

The meter would be positioned at `X=97`

. Since the first statement of `[Measure] < 1`

is false, the formula begins testing the nested formulas in order until the condition becomes true . If none of the conditions are met, the final false value of 96 would be set.