Skip to content

About

Any language calculator

Resources

Contributing

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

ย 

History

959 Commits

Folders and files

NameName
Last commit message
Last commit date
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

Link Calculator

A grammar-based expression calculator with DateTime and Currency support, built with Rust WebAssembly and React.

CI/CD Pipeline Crates.io Rust Version License: Unlicense

Live Demo

https://link-assistant.github.io/calculator/

Screenshots

Main Interface

Link.Calculator Main Interface

Arithmetic Operations

Arithmetic calculation with step-by-step explanation

DateTime Calculations

DateTime subtraction showing duration calculation

Currency Conversions

Currency arithmetic with automatic conversion

๐Ÿ“– See USE-CASES.md for more detailed examples with screenshots, including symbolic integration, math functions, dark theme, and more.

Features

Expression Parser

  • Arithmetic operations: +, -, *, /, รท, ร—, ยท, โ‹… with proper operator precedence
  • Scientific and readable numbers: 1.5e-6, 1_000_000
  • Powers and roots: 2^10, 2**10, 2ยนโฐ, โˆš81, square root of 625
  • Conventional implicit products and functions: 2ฯ€, 2x, 2(3 + 4), sqrt 16
  • Natural operators: plus, minus, times, divided by, mod, power
  • Spelled numbers and operator words in English, Russian, Hindi, Chinese and Spanish: twenty-one times two, ัˆะตัั‚ัŒ ัƒะผะฝะพะถะธั‚ัŒ ะฝะฐ ัะตะผัŒ, เคฆเคธ เคฌเคŸเคพ เคฆเฅ‹, ไบŒๅไธ‰ๅŠ ไบ”, 10 dividido por 2 (vocabulary in data/words/arithmetic-words.lino)
  • Exact big integers and factorials: 123123980921093128 * 2348023048230429324, 30!
  • Comparisons: =, ==, !=, โ‰ , <, <=, โ‰ค, >, >=, โ‰ฅ
  • Parentheses for explicit grouping: (2 + 3) * 4
  • Negative numbers: -5 + 3
  • Percentages retain their type: 200 + 10% = 220, 100 + 10% + 10% = 121, and 10% + 20% = 30%
  • Percentage questions and conversions: 180 is what % off 200, 50 to 75 is what %, 20/200 as %, and 50% as fraction
  • Percentage phrases: ten percent of fifty, 700 ัƒะฒะตะปะธั‡ะธั‚ัŒ ะฝะฐ 30 ะฟั€ะพั†ะตะฝั‚ะพะฒ, 700็š„็™พๅˆ†ไน‹ไธ‰ๅ, and 700ใฎ30ใƒ‘ใƒผใ‚ปใƒณใƒˆ
  • Decimal precision using rust_decimal

Number separators

Number conventions are resolved in the lexer before parsing or evaluation:

  • 1,234 means 1234: a comma followed by exactly three digits groups thousands when the leading group has one to three digits. Other single commas are decimal separators: 12,3 means 12.3, 1,2 means 1.2. The exact spelling 1,1 is a documented fend compatibility exception and means 11; use 1.1 for the decimal value.
  • When both . and , occur in a number, the rightmost mark is decimal: 1,234.5 and 1.234,5 both mean 1234.5.
  • Valid groups separated by spaces (including Unicode grouping spaces) or Swiss apostrophes work with either decimal convention: 1 234,5, 1'234.5, and 1โ€™234.5 all mean 1234.5.
  • Indian grouping is supported: 12,34,567 means 1234567.
  • Inside function calls every comma separates arguments, regardless of spacing: max(1,2) means 2, max(1,234) means 234, and round(1,234) supplies two arguments and reports an argument-count error. Use decimal dots and space/apostrophe grouping in arguments, e.g. round(1'234.5).
  • Planning still exposes the decimal-comma alternative for ambiguous grouped numbers; the primary interpretation of 1,234 / 100 is 12.34.

These rules apply independently to each numeric literal and do not depend on browser language. The 1,1 exception also exposes 1.1 as an alternative interpretation in planning. Binary, octal, and hexadecimal literals (including fractions such as 0b100.001) retain their numeric meaning.

Measured values such as 12,3 ยฑ 4,5 produce 12.3 ยฑ 4.5 with a non-negative absolute uncertainty. Central value and uncertainty must have matching units; arithmetic on uncertain values reports an error until propagation is supported. German Mio. and Mrd. scale by one million and one billion, respectively; 1,08 Mrd. km/h produces 1080000000 km/h, a physical speed (see below).

Physical units

Values carry a dimension vector (length, mass, time, current, temperature, amount, luminosity, information, angle, currency) and an exact scale. Units come from data/units/units.lino: SI base and derived units with all prefixes (ยตm, ฮผm, um, kฮฉ), binary prefixes (KiB), Imperial/US, electrical, information, angle and temperature units, with aliases such as feet, metres, ะผ, ะบะผ and ั‡.

  • *, /, powers and roots combine dimensions: 10m ร— 10m = 100 m^2, (5 volts) / (2 ohms) = 2.5 A, 1 mph * 1 hour = 1 mi; sqrt(2m) is an error. Addition and comparison require equal dimensions: 2m == 200cm is true.
  • Unit expressions: 299792458 mโ‹…sโˆ’1, mยทsโปยน, m s^-1, km/h, km per hour, kgยทmยฒ/sยฒ; conversions with in/to/as: 1 ft to cm = 30.48 cm, 9.81 m/sยฒ * 70 kg in N = 686.7 N.
  • Compound quantities: 5 feet 10 inches in cm = 177.8 cm, 6'2", 1 meter 20 cm.
  • Temperatures follow Numbat: 20 celsius = 293.15 K, 25 ยฐC in ยฐF = 77 ยฐF, and arithmetic on ยฐC/ยฐF such as 25 ยฐC * 2 is rejected (convert to K first).
  • m after a number is the metre and min the minute; 5m means minutes only in an explicit time context (5m in s, 1h + 5m, now + 5m).

See the issue #235 case study for the design and its documented decisions.

DateTime Support

Supports multiple date and time formats:

  • ISO format: 2026-01-22, 2025.10.15
  • US format: 01/22/2026, 01-22-2026, 10.15.2025
  • European format: 22/01/2026, 15.10.2025, 15-10-2025
  • Month names: Jan 22, 2026, 22 Jan 2026
  • Time formats: 8:59am, 14:30, with timezone support (8:59am UTC)
  • DateTime arithmetic: (Jan 27, 8:59am UTC) - (Jan 25, 12:51pm UTC)
  • Numeric dates work directly in expressions: 15.10.2025 + 180 days, 15/10/2025 + 180 days

Currency Support

  • Currency amounts: 84 USD, 34 EUR
  • Currency arithmetic with automatic conversion: 100 USD + 50 EUR
  • Temporal awareness: 84 USD - 34 EUR at 22 Jan 2026
  • Support for 50+ currencies including major world currencies, precious metals, and cryptocurrencies

Links Notation

All expressions are represented in links-notation format:

  • Step-by-step calculation explanations
  • Issue prefill links for unrecognized input

Example Usage

> 2 + 3
Result: 5
Links notation: ((2) + (3))

> (Jan 27, 8:59am UTC) - (Jan 25, 12:51pm UTC)
Result: 1 day, 20 hours, 8 minutes
Links notation: (((Jan 27, 8:59am UTC) - (Jan 25, 12:51pm UTC)))

> 84 USD - 34 EUR
Result: 47.042 USD
Links notation: (((84 USD)) - ((34 EUR)))

Technical Implementation

Rust WASM Core (src/)

  • grammar/ - Lexer and recursive descent parser
  • types/ - Value, Decimal, DateTime, Currency, Unit types
  • lino/ - Links notation representation
  • error/ - Error types with thiserror
  • wasm.rs - WebAssembly bindings

React Frontend (web/)

  • Vite + TypeScript + React 18
  • Web Worker for non-blocking WASM calculations
  • Responsive design with real-time results
  • Example expressions for quick testing

CI/CD (.github/workflows/)

  • ci.yml - Tests, linting, formatting, WASM build
  • deploy.yml - GitHub Pages deployment

Development Setup

Prerequisites

  • Rust 1.70+ with wasm32-unknown-unknown target
  • Node.js 18+
  • wasm-pack

Build & Run

# Clone the repository
git clone https://github.com/link-assistant/calculator.git
cd calculator

# Build the WASM package
wasm-pack build --target web --out-dir web/public/pkg

# Install web dependencies
cd web
npm install

# Start development server
npm run dev

Running Tests

# Run all Rust tests
cargo test

# Run tests with verbose output
cargo test --verbose

# Run Clippy lints
cargo clippy --all-targets --all-features

# Format code
cargo fmt

# Check formatting (CI style)
cargo fmt --check

Building for Production

# Build optimized WASM
wasm-pack build --target web --release --out-dir web/public/pkg

# Build web frontend
cd web
npm run build

Project Structure

.
โ”œโ”€โ”€ .github/workflows/      # CI/CD pipeline configuration
โ”œโ”€โ”€ data/                   # Currency exchange rate databases
โ”‚   โ””โ”€โ”€ exchange_rates/     # Historical exchange rates (.lino files)
โ”œโ”€โ”€ docs/                   # Documentation and screenshots
โ”œโ”€โ”€ src/                    # Rust source code
โ”‚   โ”œโ”€โ”€ grammar/            # Lexer, parser, and grammar modules
โ”‚   โ”œโ”€โ”€ types/              # Core types (Value, DateTime, Currency, etc.)
โ”‚   โ”œโ”€โ”€ lino/               # Links notation module
โ”‚   โ”œโ”€โ”€ error.rs            # Error types
โ”‚   โ”œโ”€โ”€ lib.rs              # Library entry point
โ”‚   โ”œโ”€โ”€ main.rs             # CLI entry point
โ”‚   โ””โ”€โ”€ wasm.rs             # WASM bindings
โ”œโ”€โ”€ tests/                  # Integration tests
โ”œโ”€โ”€ web/                    # React frontend
โ”‚   โ”œโ”€โ”€ src/                # TypeScript source
โ”‚   โ””โ”€โ”€ public/             # Static assets
โ”œโ”€โ”€ Cargo.toml              # Rust project configuration
โ””โ”€โ”€ README.md               # This file

Contributing

Contributions are welcome! Please see CONTRIBUTING.md for guidelines.

Development Workflow

  1. Fork the repository
  2. Create a feature branch: git checkout -b feature/my-feature
  3. Make your changes and add tests
  4. Run quality checks: cargo fmt && cargo clippy && cargo test
  5. Add a changelog fragment
  6. Commit your changes (pre-commit hooks will run automatically)
  7. Push and create a Pull Request

License

Unlicense - Public Domain

This is free and unencumbered software released into the public domain. See LICENSE for details.

Acknowledgments

About

Any language calculator

Resources

Contributing

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages