# Compare

> Compare two data values as numbers, text or lists and send true or false: ordering, equality, contains, starts or ends with, pattern match, empty, in list.

Source: https://docs.tune.toys/nodes/data.compare/

Data Compare tests two data values and sends `true` or `false`.

## What it does

Operation chooses the test. The first six, Greater, Less, Greater or equal, Less or equal, Equal and Not equal, match signal [Compare](https://docs.tune.toys/nodes/std.compare/). They compare as numbers when both values read as numbers, and otherwise as text, character by character. Equal on two lists is true when every element is equal, in order.

The rest work on text and lists. Contains is true when text A contains text B, or when list A contains B. Starts with and Ends with test the start and end of text A. Matches reads B as a regular expression and tests text A. Is empty is true for empty text, text that is only spaces, an empty list and no value; numbers and booleans are never empty. In list is true when list B contains A.

Case decides whether text tests care about upper and lower case. Compare runs whenever an input receives a value. An invalid regular expression sends no value and the inspector shows the error.

## When to use it

Use it to make decisions on data: check a setting against a limit, test whether a name contains a word, or see whether a note is in a list. For audio and control signals use signal [Compare](https://docs.tune.toys/nodes/std.compare/).

## Ports

<!-- ports:start -->

| Port     | Direction | Signal         | Lanes |
| -------- | --------- | -------------- | ----- |
| `a`      | Input     | Data (any)     | 1     |
| `b`      | Input     | Data (any)     | 1     |
| `result` | Output    | Data (boolean) | 1     |

<!-- ports:end -->

## Parameters

<!-- parameters:start -->

| Parameter | Label     | Range   | Default | Unit | Scale  | Notes                                                                                                                                                                                         |
| --------- | --------- | ------- | ------- | ---- | ------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `op`      | Operation | 0 to 11 | 0       |      | linear | Comparison of a against b. Choices: 0 Greater, 1 Less, 2 Greater or equal, 3 Less or equal, 4 Equal, 5 Not equal, 6 Contains, 7 Starts with, 8 Ends with, 9 Matches, 10 Is empty, 11 In list. |
| `epsilon` | Tolerance | 0 to 1  | 0       |      | linear | Numeric difference still counted as equal. Shown when `op` is 4 or 5.                                                                                                                         |
| `case`    | Case      | 0 to 1  | 0       |      | linear | Whether text comparisons respect letter case. Choices: 0 Sensitive, 1 Insensitive. Shown when `op` is 0 or 1 or 2 or 3 or 4 or 5 or 6 or 7 or 8 or 9.                                         |

<!-- parameters:end -->

### Operation (`op`)

The test, a discrete choice. Values 0 to 5 have the same names and order as signal Compare.

### Tolerance (`epsilon`)

For Equal and Not equal on numbers, how far apart A and B may be and still count as equal, from 0 to 1. 0 asks for exact equality. Useful when a number comes from arithmetic, where 0.1 + 0.2 is not exactly 0.3.

### Case (`case`)

Sensitive or Insensitive, a discrete choice. Insensitive folds case for text ordering, equality, Contains, Starts with and Ends with, and adds the `i` flag to Matches.

## Tips

- To check a threshold, compare a number with Greater; the result is a boolean you can send on to other data nodes.
- Matches uses JavaScript-style regular expressions: `^k` means starts with k, `[0-9]+` means one or more digits.
- B has no text field of its own; connect a [Value](https://docs.tune.toys/nodes/data.value/) to B to compare with a fixed value.

## See also

[Value](https://docs.tune.toys/nodes/data.value/), [String](https://docs.tune.toys/nodes/data.string/), [List](https://docs.tune.toys/nodes/data.list/), [Compare (signal)](https://docs.tune.toys/nodes/std.compare/).
