calculator

Use the local calculator CLI for precise math evaluation and real-time currency conversion. Always call it for math or exchange rate questions to guarantee accuracy.

1yx
開発者 1yx
その他 · TypeScript · 更新日: 4 months ago
0
スター
0
Forks
注意
CCC
安全性:
普通
BBB
品質:

name: calculator description: Use the local calculator CLI for precise math evaluation and real-time currency conversion. Always call it for math or exchange rate questions to guarantee accuracy.

Calculator Skill

When the user asks a math question or currency conversion question, ALWAYS use the calculator CLI tool instead of computing in your head. This ensures precise results using Decimal.js and real-time exchange rates from Bank of China (中行牌价).

When to Use

How to Call

Math

node ~/Repositories/calculator/dist/cli.js '<expression>'

Currency Conversion (live rates from BOC, no API key needed)

node ~/Repositories/calculator/dist/cli.js '<amount> <FROM> to <TO>'

No dotenv, no .env, no API key needed. BOC rates are scraped from the public page. Cache is stored in the project's cache/ directory, refreshed daily at 10:40 by systemd timer.

Math Examples

node ~/Repositories/calculator/dist/cli.js '0.1 + 0.2'
node ~/Repositories/calculator/dist/cli.js '2 + 3 * 4'
node ~/Repositories/calculator/dist/cli.js '(100 - 15) * 0.08'
node ~/Repositories/calculator/dist/cli.js '2 ^ 10'
node ~/Repositories/calculator/dist/cli.js '1000 * 1.08'

Currency Conversion Examples

node ~/Repositories/calculator/dist/cli.js '100 USD to CNY'
node ~/Repositories/calculator/dist/cli.js '980 EUR to CNY'
node ~/Repositories/calculator/dist/cli.js '50000 JPY -> USD'
node ~/Repositories/calculator/dist/cli.js '1000 CNY to EUR'

For multi-step problems, break them into separate calls if needed, then combine results.

Output Format

The CLI outputs the result directly for math or <amount> FROM = <amount> TO for conversions. Always start your response with the abacus emoji 🧮, then present the result clearly to the user. Do NOT add any explanation about how the calculation works, floating-point precision, or Decimal.js internals. Just give the result.

Mixed Precedence Expressions

When the expression contains mixed operators of different precedence (e.g. 2 + 3 * 4, 45 - 67 + 89 × 8, "二加上三乘以四"), this is ambiguous to a casual reader. Always return both interpretations as complete equations with the original expression on the left:

  1. 运算符优先级 (standard math): call the calculator as-is
  2. 从左到右 (left-to-right): add parentheses to force sequential left-to-right evaluation

Example — expression 45 - 67 + 89 × 8:

Example — user says "二加上三乘以四":

Only do this when the expression has operators of different precedence levels (e.g. + with *, + with ^). Pure same-level operators (e.g. 2 + 3 + 4) return a single result as usual.

Architecture

CLI Flags

Supported Currencies

USD, EUR, GBP, JPY, HKD, AUD, CAD, SGD, NZD, KRW, THB, CHF, SEK, DKK, NOK, MOP, RUB, IDR, MYR, PHP, TWD, AED, BND, BRL, ZAR, SAR, TRY + CNY

BOC Rate Cache

TypeScript Notes (TS 6 + NodeNext)

Testing

export PATH="$HOME/.local/share/fnm/node-versions/v24.14.1/installation/bin:$HOME/.local/bin:$PATH"
cd ~/Repositories/calculator && pnpm test

Uses Node.js built-in test runner (node:test) + tsx for TypeScript. Tests live in src/calculator.test.ts.

Known precision caveat: (1/3)*3 yields 0.99999999999999999999 with 20-digit Decimal.js precision, NOT 1. This is correct behavior — finite decimal truncation. Don't write a test asserting it equals 1.

Build

export PATH="$HOME/.local/share/fnm/node-versions/v24.14.1/installation/bin:$HOME/.local/bin:$PATH"
cd ~/Repositories/calculator && pnpm build
🔓 サインインしてさらに解放
GitHub でサインイン