A simple command-line calculator
-
Clone the repository:
git clone https://github.com/shakiyam/calc.git cd calc -
Run it: Use the
./calcscript to start the interactive shell. It requires Docker or Podman and will pull the necessary image automatically.Note: If you prefer not to use Docker/Podman, see the Local Python Execution section below.
$ ./calc 1 + 1 = 2 1 + ? x 3,000 = 6,001 00:01:00 + 123sec = 00:03:03 25:00:00 = 1 day and 01:00:00 exit $
Comments start with # and extend to the end of the line.
1 + 1 # This is a comment
| Operator | Description | Aliases |
|---|---|---|
+ |
Addition | + |
- |
Subtraction | - |
* |
Multiplication | x X × |
/ |
Division | ÷ |
% |
Modulo | |
** |
Exponentiation | ^ |
| Function | Description |
|---|---|
abs(n) |
Absolute value of n |
avg(a, b, ...) |
Average of all arguments |
ceil(n) |
Ceiling: smallest integer >= n |
cos(n) |
Cosine of n (in radians) |
exp(n) |
Exponential of n (e**n) |
floor(n) |
Floor: largest integer <= n |
log(n) |
Natural logarithm of n |
max(a, b, ...) |
Maximum of all arguments |
min(a, b, ...) |
Minimum of all arguments |
round(n[, d]) |
Rounds n to d decimal places (default is 0) |
sin(n) |
Sine of n (in radians) |
sqrt(n) |
Square root of n |
sum(a, b, ...) |
Sum of all arguments |
tan(n) |
Tangent of n (in radians) |
Important: When using functions with multiple arguments, include a space after each comma:
- ✅ Correct:
max(1, 2, 3)oravg(10, 20, 30) - ❌ Incorrect:
max(1,2,3)oravg(10,20,30)
| Constant | Description |
|---|---|
pi |
3.1415926535... |
e |
2.7182818284... |
calc supports comprehensive time calculations with natural language input:
- Output: Always uses
HH:MM:SSformat withandfor days:1 day and 02:00:00(microseconds shown when present)
Input format examples:
# Basic formats
01:30:45 → 01:30:45
00:01:30.500000 → 00:01:30.500000
60s → 00:01:00
30min → 00:30:00
5hr → 05:00:00
1 day → 1 day
2d → 2 days
# Compact combinations (English)
1h 30m → 01:30:00
1m 5s → 00:01:05
# Day and combinations (English)
1 day and 10 hours → 1 day and 10:00:00
1 day and 1 hour 2 min → 1 day and 01:02:00
# Natural language (English)
1 day 2 hours 30 minutes → 1 day and 02:30:00
2 hours and 30 minutes → 02:30:00
# Natural language (Japanese)
1時間 30分 → 01:30:00
1時間30分 → 01:30:00
2日 3時間 → 2 days and 03:00:00
2日3時間 → 2 days and 03:00:00
Calculation examples:
00:01:00 + 30s → 00:01:30
01:00:00 - 30s → 00:59:30
00:30:00 * 2 → 01:00:00
02:00:00 / 2 → 01:00:00
1h + 30min → 01:30:00
30min - 5s → 00:29:55
1時間 + 30分 → 01:30:00
2時間 - 15分 → 01:45:00
When running in the interactive shell (as shown in the Quick Start), you can access the previous result with the ? symbol.
Numbers are displayed with a comma as a thousands separator (e.g., 1,234,567). Input also supports numbers with thousands separators.
Non-time units after numbers are ignored, allowing natural expressions:
10個 + 20個→30100 円 - 50 円→5010.5kg * 2→21.01,024 GB / 4→256
Type exit to leave the interactive shell.
The ./calc script runs the calculator inside a container.
-
Interactive Shell Mode:
./calc
-
Direct Command Execution: Pass the expression as a single argument.
./calc '1 + 2 * 3,000'
This method is for users who prefer not to use containers.
-
Setup: From the project root directory (where this README.md is located), install the package and its dependencies using
uv.Option 1: Using virtual environment (recommended)
uv venv source .venv/bin/activate # On Windows: .venv\Scripts\activate uv pip install -e .
Option 2: System-wide installation (may require administrator privileges)
uv pip install --system -e . -
Usage: After installation, run the calculator from anywhere:
# Interactive Mode calc # Direct Command calc '1 + 2 * 3'