---
name: calculator
description: Calculator. Use when evaluating mathematical expressions.
---

# Calculator

Execute mathematical expressions in PowerShell to get calculation results.

## Quick Start

```bash
# Add
$ pwsh -nop -C "10 + 20"
30

# Subtract
$ pwsh -nop -C "20 - 10"
10

# Multiply
$ pwsh -nop -C "3 * 3 * 3 * 3"
81

# Divide
$ pwsh -nop -C "10 / 3"
3.33333333333333

# Mod
$ pwsh -nop -C "7 % 2"
1

# Integer division (Truncate towards zero)
$ pwsh -nop -C "[Math]::Truncate(5 / 2)"
2

# Banker's Rounding (round-to-nearest-even cast behavior)
$ pwsh -nop -C "[int]2.5"
2
$ pwsh -nop -C "[int]3.5"
4

# Round
$ pwsh -nop -C "[Math]::Round(123.456789, 0, [MidpointRounding]::AwayFromZero)"
123

$ pwsh -nop -C "[Math]::Round(123.456789, 1, [MidpointRounding]::AwayFromZero)"
123.5

$ pwsh -nop -C "[Math]::Round(123.456789, 2, [MidpointRounding]::AwayFromZero)"
123.46

# Ceiling
$ pwsh -nop -C "[Math]::Ceiling(5 / 2)"
3

# Floor
$ pwsh -nop -C "[Math]::Floor(5 / 2)"
2

# Exponentiation (Power)
$ pwsh -nop -C "[Math]::Pow(2, 8)"
256

# Square Root
$ pwsh -nop -C "[Math]::Sqrt(16)"
4

# Absolute Value
$ pwsh -nop -C "[Math]::Abs(-5)"
5

# Hexadecimal to Decimal
$ pwsh -nop -C "0x1A"
26

# Decimal to Hexadecimal
$ pwsh -nop -C "'0x{0:X}' -f 26"
0x1A
```

