# »Language: Values

Values are the data that Sentinel policies operate on. You can create this data yourself, for example by just typing the number `42`, or you may access this data from an external source to make policy decisions.

Values have a type, which determines what kind of operatins can be performed on the data. Example types are booleans (true and false), numbers, and strings (text).

This page documents all the available value types. You can also convert between types.

## »Boolean

A boolean is a value that is either true or false.

A boolean value is created literally with `true` or `false`.

As a policy language, booleans are central to the behavior of Sentinel. Booleans are used as conditions in if statements, are the result of rules, and more. The ultimate result of a Sentinel policy is true or false.

## »Integer

An integer is a whole number.

An integer is a 64-bit value. This means it can represent numbers from -9,223,372,036,854,775,808 to 9,223,372,036,854,775,808.

Integers are created by typing them out literally with no separators (such as a comma). An optional prefix can set a non-decimal base: `0` for octal, and `0x` for hexadecimal. In hexadecimal literals, letters `a-f` and `A-F` represent values 10 to 15.

Example integers are shown below:

``````42
0600
170141183460469
``````

Integers are used for math and numerical comparison.

## »Float

A float is a number with a decimal point. It has an integer part, a decimal point, a fractional part, and optionally an exponent part. Example floats are shown below:

``````0.
72.40
072.40  // == 72.40
2.71828
1.e+0
6.67428e-11
1E6
.25
.12345E+5
``````

Floats are IEEE-754 64-bit floating point numbers.

## »String

Strings are text values.

Strings are created by wrapping text in double quotes, such as `"hello"`. Within the quotes, any character may appear except newline and an unescaped double quote. The text between the quotes is the value.

Because Sentinel policies must be UTF-8 encoded text, strings themselves are UTF-8 encoded text. This means you can put any value UTF-8 character into a string, such as `"日本語"`.

You can have a string with a literal double-quote by escaping it with a backslash. For example: `"they said \"hello\""` turns into the value `they said "hello"`.

Backslash escapes can be used for much more than only escaping a double quote. Newlines are `\n`, a literal backslash is `\\`, and many more. The full list of available backslash escapes can be found in the language specification.

Example strings:

```````abc`                // same as "abc"
`\n
\n`                  // same as "\\n\n\\n"
"\n"
"\""                 // same as `"`
"Hello, world!\n"
"日本語"
"\u65e5本\U00008a9e"
"\xff\u00FF"
"\uD800"             // illegal: surrogate half
"\U00110000"         // illegal: invalid Unicode code point
``````

Strings support indexing. Indexing a string will access that byte in the string as if the string were a byte array. This is an important distinction: it will not access the character at that position if you're using multi-byte characters.

Strings support slicing to efficiently create substrings.

See Lists.

See Maps.

See Rules.

See Functions.

## »Type Conversion

The built-in functions `int`, `float`, `string`, and `bool` convert a value to a value of that type. Some examples are shown below followed by a list of exact rules for type conversion.

``````int(42)   // 42
int("42") // 42
int(42.8) // 42
int(true) // 1

float(1.2)   // 1.2
float(1)     // 1.0
float("4.2") // 4.2
float(true)  // 1.0

string("foo") // "foo"
string(88)    // "88"
string(0xF)   // "15"
string(true)  // "true"

bool("true")  // true
bool(1)       // true
bool(-1)      // true
bool(0.1)     // true
bool("false") // false
bool(0)       // false
``````

For `int`:

• Integer values are unchanged
• String values are converted according to the syntax of integer literals
• Float values are rounded down to their nearest integer value
• Boolean values are converted to `1` for `true`, and `0` for `false`

For `float`:

• Float values are unchanged
• Integer values are converted to the nearest equivalent floating point value
• String values are converted according to the syntax of float literals
• Boolean values are converted to `1.0` for `true`, and `0.0` for `false`

For `string`:

• String values are unchanged
• Integer values are converted to the base 10 string representation
• Float values are converted to a string formatted `xxx.xxx` with a precision of 6. This is equivalent to `%f` for C's sprintf.
• Boolean values are converted to `"true"` for `true`, and `"false"` for `false`

For `bool`:

• The following string values convert to `true`: `"1"`, `"t"`, `"T"`, `"TRUE"`, `"true"`, and `"True"`
• The following string values convert to `false`: `"0"`, `"f"`, `"F"`, `"FALSE"`, `"false"`, and `"False"`
• Any non-zero integer or float value converts to `true`
• Any zero integer or float value converts to `false`

For any other unspecified type, the result is the `undefined` value.