# Operators

Operators can be used to construct formulas. Deephaven gives users access to all of Java's operators, including:

## Arithmetic operators

Symbol | Name | Description |
---|---|---|

`+` | Addition | Adds values. |

`-` | Subtraction | Subtracts the right value from the left value. |

`*` | Multiplication | Multiplies the left and right values. |

`/` | Division | Divides the left value by the right value. |

`%` | Modulus | Divides the left value by the right value and returns the remainder. |

## Access operators

Symbol | Name | Description |
---|---|---|

`_` | Underscore | Accesses an array of all values within the column. |

`[]` | Index | Indexes array elements. |

`.` | Dot | Accesses members of a package or a class. |

## Comparison operators

Symbol | Name | Description |
---|---|---|

`==` | Equal to | Compares two values to see if they are equal. |

`!=` | Not equal to | Compares two values to see if they are not equal. |

`>` | Greater than | Compares two values to see if the left value is greater than the right value. |

`>=` | Greater than or equal | Compares two values to see if the left value is greater than or equal to the right value. |

`<` | Less than | Compares two values to see if the left value is less than the right value. |

`<=` | Less than or equal | Compares two values to see if the left value is less than or equal to the right value. |

## Assignment operators

Symbol | Name | Description |
---|---|---|

`=` | Assignment | Assigns a value to a variable. |

`+=` | Addition assignment | Adds the right operand to the left operand and assigns the result to the left operand. |

`-=` | Subtraction assignment | Subtracts the right operand from the left operand and assigns the result to the left operand. |

`++` | Increment | Adds one to the value of the operand. |

`--` | Decrement | Subtracts one from the value of the operand. |

`*=` | Multiplication assignment | Multiplies the left operand by the right operand and assigns the result to the left operand. |

`/=` | Division assignment | Divides the left operand by the right operand and assigns the result to the left operand. |

`%=` | Modulus assignment | Divides the left operand by the right operand and assigns the remainder to the left operand. |

## Logical operators

Symbol | Name | Description |
---|---|---|

`!` | Logical NOT | Inverts the value of a boolean. |

`&&` | Logical AND | Returns true if both operands are true. |

`||` | Logical OR | Returns true if either operand is true. |

## Bitwise operators

Symbol | Name | Description |
---|---|---|

`~` | Bitwise complement | A unary operator that 'flips' bits. |

`&` | Bitwise AND | Compares each bit of the first operand to the corresponding bit of the second operand. If both bits are 1, the corresponding result bit is set to 1. Otherwise, the corresponding result bit is set to 0. |

`<<` | Left shift | The left operand's value is shifted left by the number of bits set by the right operand. |

`>>` | Right shift | The left operand's value is shifted right by the number of bits set by the right operand. |

`^` | Bitwise XOR | Compares each bit of the first operand to the corresponding bit of the second operand. If the bits are different, the corresponding result bit is set to 1. Otherwise, the corresponding result bit is set to 0. |

`&=` | Bitwise AND assignment | Performs a bitwise AND on the left and right operands and assigns the result to the left operand. |

`^=` | Bitwise XOR assignment | Performs a bitwise XOR on the left and right operands and assigns the result to the left operand. |

## Other Java operators

Symbol | Name | Description |
---|---|---|

`(type)` | Casting | Casts from one type to another. |

`()` | Function call | Calls a function. |

`->` | Java Lambda | Defines a Java lambda function. |

`?:` | Ternary conditional | Returns one of two values depending on the value of a boolean expression. |

`instanceof` | Instance of | Returns true if the object is an instance of the class. |

## Example

In this example, operators are used with objects to create new columns of values.

`from deephaven import empty_table`

class MyObj:

def __init__(self, a, b, c):

self.a = a

self.b = b

self.c = c

def compute(self, value1):

return self.a + value1

obj = MyObj(1, 2, 3)

result = empty_table(10).update(

formulas=[

"A = i",

"B = A * A",

"C = A / 2",

"D = A % 3",

"E = (int)C",

"F = A_[i-2]",

"G = obj.a",

"H = obj.compute(A)",

"I = sqrt(A)",

]

)

- result

In this example, comparison operators are used to grab specific integers from a table.

`from deephaven import new_table`

from deephaven.column import int_col

source = new_table([int_col("Value", [0, 1, 2, 3, 4, 5, 6])])

greater_than = source.where(filters=["Value > 3"])

greater_than_or_equal = source.where(filters=["Value >= 3"])

less_than = source.where(filters=["Value < 3"])

less_than_or_equal = source.where(filters=["Value <= 3"])

- source
- greater_than
- greater_than_or_equal
- less_than
- less_than_or_equal