> ## Documentation Index
> Fetch the complete documentation index at: https://fhenix-docs-broken-sample-fixes.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Arithmetic Operations

> add, sub, mul, div, rem, and square: encrypted math operations

All arithmetic operations work on `euint8 | euint16 | euint32 | euint64 | euint128`. Both operands must be the same type.

## add

```solidity theme={null}
euint32 sum = FHE.add(a, b);
```

## sub

```solidity theme={null}
euint32 diff = FHE.sub(a, b);
```

## mul

```solidity theme={null}
euint32 product = FHE.mul(a, b);
```

## div

<Warning>
  Division by zero does not revert. The FHE Engine cannot inspect the encrypted divisor, so `div` returns the maximum value of the operand type instead (255 for `euint8`). If that result is wrong for your contract, test the divisor with `eq` and pick a fallback with `select`.
</Warning>

```solidity theme={null}
euint32 quotient = FHE.div(a, b);
```

## rem

<Note>
  Remainder by zero does not revert. `rem` returns the dividend unchanged, so `63 % 0` yields `63`. The mock contracts behind the Hardhat and Foundry plugins differ here: they revert with a Solidity division panic. A local test of `rem` by zero therefore fails while the same call succeeds on a live network.
</Note>

```solidity theme={null}
euint32 remainder = FHE.rem(a, b);
```

## square

```solidity theme={null}
euint32 squared = FHE.square(a);
```
