summaryrefslogtreecommitdiff
path: root/docs
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2026-05-24 23:10:22 +0300
committerPaul Buetow <paul@buetow.org>2026-05-24 23:10:22 +0300
commit50bff2ffa7a09f3ae35b10219b49d5cf38457066 (patch)
tree997173667c42b78d902ce8f715d52af72b238e6a /docs
parentdc89fa2bbcdea7c8847828f64be5e46ddded33fb (diff)
docs: de-LLM all .md files - remove corporate language, over-explanation, and LLM patterns
Diffstat (limited to 'docs')
-rw-r--r--docs/basic-arithmetic.md92
-rw-r--r--docs/cli-usage.md76
-rw-r--r--docs/comparisons.md110
-rw-r--r--docs/constants.md8
-rw-r--r--docs/custom-metrics.md55
-rw-r--r--docs/fast-power.md2
-rw-r--r--docs/hyper-operators.md114
-rw-r--r--docs/log-operators.md67
-rw-r--r--docs/metric-commands.md16
-rw-r--r--docs/metrics.md2
-rw-r--r--docs/percentage-calculations.md54
-rw-r--r--docs/repl-mode.md2
-rw-r--r--docs/stack-operations.md60
-rw-r--r--docs/symbols.md9
-rw-r--r--docs/unit-conversion.md34
-rw-r--r--docs/variables.md9
16 files changed, 115 insertions, 595 deletions
diff --git a/docs/basic-arithmetic.md b/docs/basic-arithmetic.md
index 162d10f..4e22386 100644
--- a/docs/basic-arithmetic.md
+++ b/docs/basic-arithmetic.md
@@ -1,9 +1,6 @@
# Basic Arithmetic RPN Operators
-`gt` evaluates expressions using Reverse Polish Notation (RPN), a stack-based
-calculation method where operators follow their operands. No parentheses are
-needed, and the order of operations is determined entirely by the sequence of
-tokens.
+gt evaluates expressions using Reverse Polish Notation (RPN), a stack-based calculation method where operators follow their operands. No parentheses needed — the token sequence determines the order of operations.
## How RPN Works
@@ -12,8 +9,7 @@ Each token is processed left to right:
1. **Numbers** are pushed onto the stack.
2. **Operators** pop the required operands, compute the result, and push it back.
-For example, `3 4 +` pushes 3, then 4, then `+` pops both (3 and 4), adds
-them, and pushes the result (7).
+For example, `3 4 +` pushes 3, then 4, then `+` pops both, adds them, and pushes 7.
### Stack visualization
@@ -31,9 +27,7 @@ Result: 7
## Operators
-All binary arithmetic operators pop two values and push one result. The
-**first** value pushed is the left operand (`a`), and the **second** value
-pushed is the right operand (`b`). The operation is always `a <op> b`.
+All binary arithmetic operators pop two values and push one result. The **first** value pushed is the left operand (`a`), the **second** is the right operand (`b`). The operation is always `a <op> b`.
### `+` Addition
@@ -44,16 +38,13 @@ $ gt '3 4 +'
### `-` Subtraction
-Computes `a - b` (first value minus second value).
+Computes `a - b` (first value minus second). Order matters:
```
$ gt '3 4 -'
-1
```
-Note: order matters in RPN subtraction. `3 4 -` yields `-1` because it
-computes `3 - 4`.
-
### `*` Multiplication
```
@@ -63,7 +54,7 @@ $ gt '5 6 *'
### `/` Division
-Computes `a / b` (first value divided by second value).
+Computes `a / b` (first value divided by second).
```
$ gt '20 4 /'
@@ -72,26 +63,15 @@ $ gt '20 4 /'
### `^` Power
-Computes `a ^ b` (first value raised to the power of the second). Result is
-always unitless.
+Computes `a ^ b` (first value raised to the power of the second). Result is always unitless.
```
$ gt '2 3 ^'
8
-```
-
-Additional examples:
-
-```
$ gt '2 10 ^'
1024
$ gt '5 0 ^'
1
-```
-
-Supports negative exponents:
-
-```
$ gt '2 -3 ^'
0.125
```
@@ -103,11 +83,6 @@ Computes `a % b` (remainder of `a / b`).
```
$ gt '10 3 %'
1
-```
-
-Additional examples:
-
-```
$ gt '7 3 %'
1
$ gt '13 5 %'
@@ -118,7 +93,7 @@ $ gt '100 7 %'
## Multi-operand Expressions
-RPN naturally handles complex expressions without parentheses.
+RPN handles complex expressions without parentheses.
### Chained operations
@@ -127,16 +102,14 @@ $ gt '1 2 3 + +'
6
```
-Step by step: `1` pushed, `2` pushed, `3` pushed, `+` pops 2 and 3
-producing 5 (stack: `[1, 5]`), `+` pops 1 and 5 producing 6.
+Step by step: `1` pushed, `2` pushed, `3` pushed, `+` pops 2 and 3 producing 5 (stack: `[1, 5]`), `+` pops 1 and 5 producing 6.
```
$ gt '10 2 3 - *'
-10
```
-Step by step: `10` pushed, `2` pushed, `3` pushed, `-` pops 2 and 3
-producing -1 (stack: `[10, -1]`), `*` pops 10 and -1 producing -10.
+Step by step: `10` pushed, `2` pushed, `3` pushed, `-` pops 2 and 3 producing -1 (stack: `[10, -1]`), `*` pops 10 and -1 producing -10.
### Nested operations
@@ -156,15 +129,14 @@ This is `2^3 + 4^5` = `8 + 1024` = `1032`.
### Order of operations
-In RPN, the order of operations is explicit in the token sequence:
+In RPN, the order is explicit in the token sequence:
```
$ gt '10 3 2 * /'
1.666666667
```
-This computes `10 / (3 * 2)` = `10 / 6`. The inner operation `3 2 *` is
-evaluated first because the `*` comes before `/`.
+This computes `10 / (3 * 2)` = `10 / 6`. The inner operation `3 2 *` is evaluated first because `*` comes before `/`.
```
$ gt '100 10 / 5 +'
@@ -182,7 +154,7 @@ $ gt '1 2 + 3 4 + * 5 6 + +'
Breakdown: `(1+2) * (3+4) + (5+6)` = `3 * 7 + 11` = `21 + 11` = `32`.
-## Practical Use Cases
+## Examples
### Compound calculations
@@ -193,21 +165,6 @@ $ gt '10 5 + 3 * 20 4 / -'
35
```
-Stack trace:
-```
- Token Stack
- ----- -----
- 10 [10]
- 5 [10, 5]
- + [15]
- 3 [15, 3]
- * [45]
- 20 [45, 20]
- 4 [45, 20, 4]
- / [45, 5]
- - [40]
-```
-
### Geometry
Circle area (pi * r^2):
@@ -242,7 +199,7 @@ $ gt '10 20 30 + + 3 /'
### Division by zero
-Returns an error rather than infinity or NaN:
+Returns an error:
```
$ gt '5 0 /'
@@ -260,16 +217,9 @@ Error: modulo by zero
### Negative results
-Subtraction produces negative numbers naturally:
-
```
$ gt '3 7 -'
-4
-```
-
-Multiplication with negative numbers works as expected:
-
-```
$ gt '-5 3 *'
-15
```
@@ -286,22 +236,6 @@ $ gt '5 +'
Error: stack has insufficient operands
```
-### Power special cases
-
-Any number to the power of 0 yields 1:
-
-```
-$ gt '5 0 ^'
-1
-```
-
-Negative exponents produce fractional results:
-
-```
-$ gt '2 -3 ^'
-0.125
-```
-
## Summary Table
| Operator | RPN | Infix | Description | Example result |
diff --git a/docs/cli-usage.md b/docs/cli-usage.md
index b551083..0bbb938 100644
--- a/docs/cli-usage.md
+++ b/docs/cli-usage.md
@@ -1,6 +1,6 @@
# CLI Usage
-gt supports several invocation modes for different use cases: single-expression evaluation, interactive REPL, piping, and stdin redirection.
+gt supports several invocation modes: single-expression evaluation, interactive REPL, piping, and stdin redirection.
## Invocation Modes
@@ -14,7 +14,7 @@ gt '20% of 150' # → 30
gt '100Mbps @Gbps convert' # → 1
```
-This is the primary mode for scripts, one-off calculations, and CI pipelines. Each invocation starts with a fresh state — no variables, no history, no persistent settings.
+This is the primary mode for scripts, one-off calculations, and CI pipelines. Each invocation starts fresh — no variables, no history.
### REPL Mode
@@ -26,7 +26,7 @@ gt
This starts the interactive Read-Eval-Print Loop with command history, tab completion, and persistent variable storage. See [repl-mode.md](repl-mode.md) for full details.
-When stdin is not a terminal (e.g., piped input), gt falls back to single-command mode instead of starting the REPL.
+When stdin is not a terminal (e.g., piped input), gt falls back to single-command mode.
### Pipe Mode
@@ -38,18 +38,15 @@ echo '20% of 150' | gt # → 30
echo '100kmh @mph convert' | gt # → 62.13711922
```
-gt reads from stdin, trims whitespace, tries RPN parsing first, then falls back to percentage calculation. This makes it easy to integrate gt into shell pipelines.
+gt reads from stdin, trims whitespace, tries RPN parsing first, then falls back to percentage calculation.
### Stdin Redirection
-Redirect a file or use `/dev/stdin`:
-
```bash
gt < input.txt
-gt /dev/stdin < input.txt
```
-The `readStdin()` function in `cmd/gt/main.go` uses `os.ReadFile("/dev/stdin")` for full reads, with a 4096-byte buffer fallback if `/dev/stdin` is unavailable on the platform.
+gt uses `os.ReadFile("/dev/stdin")` for full reads, with a 4096-byte buffer fallback if `/dev/stdin` is unavailable.
### Empty Input
@@ -71,8 +68,6 @@ Error: no input provided
### Version
-Print the current version:
-
```bash
$ gt version
v0.4.2
@@ -89,14 +84,7 @@ $ gt -h
Error: rpn fallback failed for input "-h": perc: unable to parse input "-h": unknown error
```
-To see usage information, provide empty input or just run `gt` with no stdin:
-
-```bash
-$ echo '' | gt
-Usage: gt <calculation>
- gt version
-...
-```
+To see usage information, provide empty input or just run `gt` with no stdin.
### `--log` Flag
@@ -110,7 +98,7 @@ See [repl-mode.md](repl-mode.md) for details on session logging.
## Boolean Coercion
-gt treats `true` and `false` as first-class literals on the RPN stack. Comparison operators (`==`, `!=`, `>`, `<`, `>=`, `<=`) produce boolean values. Booleans coerce to numbers when used in arithmetic: `true` is `1`, `false` is `0`.
+gt treats `true` and `false` as first-class literals on the RPN stack. Comparison operators produce boolean values. Booleans coerce to numbers in arithmetic: `true` is `1`, `false` is `0`.
### Boolean Literals
@@ -125,27 +113,19 @@ gt 'false' # → false
gt '5 5 ==' # → true
gt '5 6 ==' # → false
gt '5 3 >' # → true
-gt '3 5 <' # → true
-gt '5 5 >' # → false
```
### Boolean-Arithmetic Coercion
-When a boolean is used with an arithmetic operator, it is coerced to `1` (true) or `0` (false):
-
```bash
gt 'true true +' # → 2 (1 + 1)
gt 'true false +' # → 1 (1 + 0)
gt 'false false +' # → 0 (0 + 0)
gt 'true 2 *' # → 2 (1 * 2)
-gt 'false 1 +' # → 1 (0 + 1)
-gt 'false 0 +' # → 0 (0 + 0)
```
### Mixed Boolean-Arithmetic Expressions
-Use comparison results directly in arithmetic without explicit conversion:
-
```bash
gt '5 3 == 1 +' # → 1 (false + 1 = 0 + 1)
gt '5 5 == 10 *' # → 10 (true * 10 = 1 * 10)
@@ -153,20 +133,12 @@ gt '5 5 == 10 *' # → 10 (true * 10 = 1 * 10)
### Comparing Booleans to Numbers
-Equality comparisons work between booleans and their numeric equivalents:
-
```bash
gt 'true 1 ==' # → true (1 == 1)
gt 'false 0 ==' # → true (0 == 0)
gt 'true 0 ==' # → false (1 != 0)
```
-### Implementation Details
-
-Boolean values are stored as a special `Float` variant (or `Rat` in rational mode) with an `isBool` flag. The `Float64()` method coerces `true` to `1` and `false` to `0` automatically. The `String()` method returns `"true"` or `"false"` instead of a numeric representation, preserving readability on the stack.
-
-See `internal/rpn/number.go` for the `Float` and `Rat` boolean implementations, and `internal/rpn/rpn_parse.go` for the `pushLiteral()` function that recognizes `true` and `false` tokens.
-
## Exit Codes
| Condition | Exit Code |
@@ -175,14 +147,12 @@ See `internal/rpn/number.go` for the `Float` and `Rat` boolean implementations,
| Error (parse failure, invalid expression, etc.) | 1 |
| Empty input (no TTY) | 1 |
-Error messages are printed to stdout with the prefix `Error:` followed by a newline and the result.
+Error messages are printed to stdout with the prefix `Error:`.
-## Practical Use Cases
+## Examples
### In Shell Scripts
-Embed calculations directly in scripts:
-
```bash
THRESHOLD=$(gt '100Mbps 50 /')
if [ "$THRESHOLD" -gt 1000 ]; then
@@ -192,8 +162,6 @@ fi
### In CI Pipelines
-Validate calculations in build steps:
-
```yaml
- name: Check bandwidth math
run: |
@@ -203,40 +171,16 @@ Validate calculations in build steps:
### In Pipes
-Combine with other tools:
-
```bash
cat sizes.txt | xargs -I{} gt '{} @GB convert'
-find . -type f -exec wc -c {} + | awk '{print $1}' | xargs -I{} gt '{} @MiB convert'
```
### Quick Conversions at the Prompt
```bash
-# Travel planning
gt '500mi @km convert' # → 804.672
-
-# Data transfer
-gt '10GB 2hr /' # → transfer rate
-
-# Weight
-gt '150lb @kg convert' # → 68.04
-
-# Percentage
gt '15% of 899' # → discount amount
-```
-
-### Conditional Logic
-
-Use boolean coercion for inline conditionals:
-
-```bash
-# Check if a value meets a threshold
gt '75 80 >' # → false (75 < 80)
-gt '85 80 >' # → true (85 > 80)
-
-# Combine with arithmetic
-gt '75 80 > 1 -' # → 1 (not greater, so 1 - false = 1 - 0 = 1)
```
## Summary of Modes
@@ -245,6 +189,6 @@ gt '75 80 > 1 -' # → 1 (not greater, so 1 - false = 1 - 0 = 1)
|------|---------|-------|----------|
| Single-expression | `gt '3 4 +'` | Fresh per invocation | Scripts, CI, one-off math |
| REPL | `gt` (with TTY) | Persistent (saved to disk) | Interactive exploration |
-| Pipe | `echo '3 4 +' \| gt` | Fresh per invocation | Pipelines, xargs |
+| Pipe | `echo '3 4 +' | gt` | Fresh per invocation | Pipelines, xargs |
| Stdin redirect | `gt < file.txt` | Fresh per invocation | Batch processing |
| Version | `gt version` | N/A | Checking installed version |
diff --git a/docs/comparisons.md b/docs/comparisons.md
index 3c990a7..0f82ec2 100644
--- a/docs/comparisons.md
+++ b/docs/comparisons.md
@@ -1,9 +1,6 @@
# Comparison RPN Operators
-`gt` provides six comparison operators, each with both a named and a symbolic
-alias. All operators are metric-aware — they convert values to base units
-before comparing. Results are boolean (`true` / `false`) and coerce
-seamlessly into arithmetic (true → 1, false → 0).
+gt provides six comparison operators, each with both a named and a symbolic alias. All operators are metric-aware — they convert values to base units before comparing. Results are boolean (`true` / `false`) and coerce into arithmetic (true → 1, false → 0).
## Operators
@@ -16,8 +13,7 @@ seamlessly into arithmetic (true → 1, false → 0).
| `eq` | `==` | `a b eq` | `a == b`| Equal |
| `neq` | `!=` | `a b neq` | `a != b`| Not equal |
-All operators pop two values (`a` first, then `b`) from the stack, compare
-them, and push the boolean result.
+All operators pop two values (`a` first, then `b`) from the stack, compare them, and push the boolean result.
## Truth Table
@@ -44,13 +40,6 @@ true
| 5 | 3 | false |
| 5 | 5 | false |
-```
-$ gt '3 5 lt'
-true
-$ gt '3 5 <'
-true
-```
-
### `gte` / `>=`
| a | b | Result |
@@ -59,13 +48,6 @@ true
| 5 | 5 | true |
| 3 | 5 | false |
-```
-$ gt '5 5 gte'
-true
-$ gt '5 3 >='
-true
-```
-
### `lte` / `<=`
| a | b | Result |
@@ -74,13 +56,6 @@ true
| 5 | 5 | true |
| 5 | 3 | false |
-```
-$ gt '5 5 lte'
-true
-$ gt '3 5 <='
-true
-```
-
### `eq` / `==`
| a | b | Result |
@@ -88,13 +63,6 @@ true
| 5 | 5 | true |
| 5 | 3 | false |
-```
-$ gt '5 5 eq'
-true
-$ gt '5 5 =='
-true
-```
-
### `neq` / `!=`
| a | b | Result |
@@ -102,17 +70,9 @@ true
| 5 | 3 | true |
| 5 | 5 | false |
-```
-$ gt '5 3 neq'
-true
-$ gt '5 3 !='
-true
-```
-
## Metric-Aware Comparison
-Comparison operators convert operands to base units before comparing, so
-different units within the same category can be compared directly.
+Comparison operators convert operands to base units before comparing, so different units within the same category can be compared directly.
### Same category, different units
@@ -136,8 +96,7 @@ $ gt '1GB 1024MB eq'
false
```
-`1GB` equals exactly `1000MB` (decimal SI), so `gt` is false and `gte` is
-true. `1024MB` is not equal to `1GB`.
+`1GB` equals exactly `1000MB` (decimal SI), so `gt` is false and `gte` is true. `1024MB` is not equal to `1GB`.
### Network throughput
@@ -157,19 +116,11 @@ $ gt '5m 3kg gt'
Error: incompatible metric categories
```
-Examples of incompatible pairs:
-
-- Distance vs. weight: `1km 5kg >`
-- Time vs. bandwidth: `1hr 100Mbps <`
-- Mass vs. distance: `10lb 5mi >=`
-
Unitless numbers are always compatible with any metric value.
## Boolean Coercion in Arithmetic
-Boolean results are represented as floating-point numbers: `true` → 1,
-`false` → 0. This allows comparison results to flow directly into arithmetic
-without explicit conversion.
+Boolean results coerce to numbers: `true` → 1, `false` → 0. This lets comparison results flow directly into arithmetic.
### Conditional addition
@@ -192,17 +143,10 @@ $ gt '3 5 gt 1 +'
```
$ gt '5 3 gt 10 *'
10
-```
-
-`5 > 3` is true (1), so `1 * 10 = 10`.
-
-```
$ gt '3 5 gt 10 *'
0
```
-`3 > 5` is false (0), so `0 * 10 = 0`.
-
### Chained comparisons
```
@@ -217,23 +161,14 @@ $ gt '9 3 gt 4 5 lt +'
```
$ gt '5 3 gt 0 -'
1
-```
-
-`5 > 3` (true/1) - 0 = 1.
-
-```
$ gt '5 5 eq 1 -'
0
```
-`5 == 5` (true/1) - 1 = 0.
-
-## Practical Use Cases
+## Examples
### Threshold checks
-Test whether a value exceeds a threshold:
-
```
$ gt '85 80 gt'
true
@@ -241,13 +176,6 @@ true
CPU at 85%, threshold at 80% — alert.
-```
-$ gt '50 10 gte'
-true
-```
-
-Disk free at 50%, minimum at 10% — OK.
-
### Range validation
Check that a value falls within acceptable bounds:
@@ -257,24 +185,19 @@ $ gt '72 68 gte 100 lte +'
2
```
-Temperature 72°F: `72 >= 68` (true/1) + `72 <= 100` (true/1) = 2 (both
-checks pass).
+Temperature 72°F: `72 >= 68` (true/1) + `72 <= 100` (true/1) = 2 (both checks pass).
```
$ gt '105 68 gte 100 lte +'
1
```
-Temperature 105°F: `105 >= 68` (true/1) + `105 <= 100` (false/0) = 1
-(outside range).
+Temperature 105°F: `105 >= 68` (true/1) + `105 <= 100` (false/0) = 1 (outside range).
-When the sum is 2, the value is within range. Any other result means at
-least one check failed.
+When the sum is 2, the value is within range. Any other result means at least one check failed.
### Metric validation
-Validate that a metric measurement meets requirements:
-
```
$ gt '100Mbps 50Mbps gt'
true
@@ -282,13 +205,6 @@ true
Download speed 100Mbps exceeds minimum 50Mbps — pass.
-```
-$ gt '2hr 1hr gte'
-true
-```
-
-Battery life 2hr meets minimum 1hr requirement — pass.
-
### Counting conditions
Sum boolean results to count how many conditions are met:
@@ -350,11 +266,3 @@ Error: stack is empty
$ gt '5 gt'
Error: stack has insufficient operands
```
-
-## Summary
-
-Comparison operators provide boolean results that integrate naturally into
-RPN arithmetic. The metric-aware design lets you compare values across units
-automatically, while the symbolic aliases (`>`, `<`, `>=`, `<=`, `==`,
-`!=`) offer familiar notation alongside the named operators (`gt`, `lt`,
-`gte`, `lte`, `eq`, `neq`).
diff --git a/docs/constants.md b/docs/constants.md
index effb71b..264e2cd 100644
--- a/docs/constants.md
+++ b/docs/constants.md
@@ -1,6 +1,6 @@
# Constants
-The gt calculator includes a comprehensive set of built-in mathematical constants that can be used directly in RPN expressions. Constants are resolved automatically — just use the name as a token.
+gt includes these built-in mathematical constants. They're resolved automatically — just use the name as a token.
## Built-in Constants
@@ -81,9 +81,9 @@ Lists all 36 built-in constants with their values, sorted alphabetically.
gt 'clearconstants'
```
-Removes all user-defined constants and resets built-in constants to their default values. Built-in constants cannot be permanently deleted.
+Removes all user-defined constants and resets built-in constants to their default values. Built-in constants can't be permanently deleted.
-## Practical Use Cases
+## Examples
### Geometry
@@ -140,4 +140,4 @@ gt 'pi' # → 3.141592654 (constant restored)
- Constants are resolved before variables in the lookup order
- All constants use float64 precision (10 significant digits in output)
- Greek letter aliases are fully supported for the most common constants
-- Built-in constants cannot be individually deleted, only overwritten with variables
+- Built-in constants can't be individually deleted, only overwritten with variables
diff --git a/docs/custom-metrics.md b/docs/custom-metrics.md
index abef141..a830d37 100644
--- a/docs/custom-metrics.md
+++ b/docs/custom-metrics.md
@@ -1,8 +1,8 @@
# Custom Metrics
-The `custom` command lets you define your own units of measurement. Custom metrics behave like built-in metrics — they support suffix notation (`10foobar`), metric-aware arithmetic, and conversion to their base unit. They are particularly useful for domain-specific units that gt doesn't ship with out of the box.
+The `custom` command lets you define your own units of measurement. Custom metrics behave like built-in metrics — they support suffix notation (`10foobar`), metric-aware arithmetic, and conversion to their base unit. They're useful for domain-specific units that gt doesn't ship with.
-Custom metrics are RPN operators — they work on the stack, consume tokens, and produce string output. They can be used in single-command mode (`./gt '<expression>'`) or interactively in REPL mode (`./gt`).
+Custom metrics are RPN operators — they work on the stack, consume tokens, and produce string output. They work in single-command mode (`gt '<expression>'`) or interactively in REPL mode (`gt`).
## `custom define`
@@ -25,12 +25,6 @@ gt 'custom define myhour 3600 Time'
gt 'custom define widget 0.5 Universal'
# → defined custom metric "widget" (factor: 0.5, category: Universal)
-
-gt 'custom define negtest -5 Custom'
-# → defined custom metric "negtest" (factor: -5, category: Custom)
-
-gt 'custom define zerounit 0 Custom'
-# → defined custom metric "zerounit" (factor: 0, category: Custom)
```
The factor determines how many base units one unit of the custom metric equals. For example, `foobar` with factor 42 means `1foobar = 42 Custom_base`.
@@ -59,7 +53,7 @@ gt 'custom define foobar 42 Custom'
## `custom undefine`
-Remove a previously defined custom metric. Built-in metrics cannot be removed.
+Remove a previously defined custom metric. Built-in metrics can't be removed.
```bash
gt 'custom undefine <name>'
@@ -112,13 +106,6 @@ gt 'custom show [name]'
### Show all custom metrics
-```bash
-gt 'custom show'
-# → no custom metrics defined
-```
-
-In REPL mode after defining metrics:
-
```
> custom define foobar 42 Custom
defined custom metric "foobar" (factor: 42, category: Custom)
@@ -163,20 +150,16 @@ defined custom metric "foobar" (factor: 42, category: Custom)
Custom metrics in the same category are compatible for addition and subtraction. The result uses the unit of the bottom-of-stack operand:
```
-> custom define foobar 42 Custom
-defined custom metric "foobar" (factor: 42, category: Custom)
> 10foobar 5foobar +
15
> 5foobar 3foobar -
2
```
-The result is unitless because the metric system resolves to base units for the calculation. For factor 42: `10foobar = 420`, `5foobar = 210`, so `420 + 210 = 630` which is `15 foobar` in base units. The displayed value is the quotient in terms of the result's unit.
+The result is unitless because the metric system resolves to base units for the calculation. For factor 42: `10foobar = 420`, `5foobar = 210`, so `420 + 210 = 630` which is `15 foobar` in base units.
### Multiplication and division
-Custom metrics work with multiplication and division:
-
```
> custom define mul_unit 5 Custom
defined custom metric "mul_unit" (factor: 5, category: Custom)
@@ -193,15 +176,13 @@ defined custom metric "div_unit" (factor: 10, category: Custom)
Unitless values (`Cool`/Universal) can be added to custom metrics:
```
-> custom define foobar 42 Custom
-defined custom metric "foobar" (factor: 42, category: Custom)
> 10foobar 5 +
10
```
### Incompatible categories
-Custom metrics in different categories cannot be mixed:
+Custom metrics in different categories can't be mixed:
```
> custom define timetest 3600 Time
@@ -217,8 +198,6 @@ Error: metric arithmetic requires compatible categories (Time vs Distance)
Custom metrics support `@<unit> convert` within their category. Conversion to a different category fails:
```
-> custom define foobar 42 Custom
-defined custom metric "foobar" (factor: 42, category: Custom)
> 10foobar @Custom_base convert
420
> 10foobar @Mbps convert
@@ -236,14 +215,12 @@ defined custom metric "hyper_test" (factor: 100, category: Custom)
18
```
-## Practical Use Cases
+## Examples
### Company-specific units
-Define internal measurement units that aren't standard:
-
```
-> custom define reel 304.8 meters
+> custom define reel 304.8 Distance
defined custom metric "reel" (factor: 304.8, category: Distance)
> 5reel @m convert
1524
@@ -251,8 +228,6 @@ defined custom metric "reel" (factor: 304.8, category: Distance)
### Recipe and cooking units
-Create convenient cooking measurements:
-
```
> custom define cup 240 Weight
defined custom metric "cup" (factor: 240, category: Weight)
@@ -264,8 +239,6 @@ defined custom metric "cup" (factor: 240, category: Weight)
### Game currencies and points
-Define game-specific units for calculating rewards:
-
```
> custom define gold 1000 Universal
defined custom metric "gold" (factor: 1000, category: Universal)
@@ -275,8 +248,6 @@ defined custom metric "gold" (factor: 1000, category: Universal)
### Time conversions with custom units
-Create convenient time units:
-
```
> custom define fortnight 1209600 Time
defined custom metric "fortnight" (factor: 1209600, category: Time)
@@ -293,10 +264,6 @@ Defining a metric with a name that already exists (including built-in metrics) f
```bash
gt 'custom define Mbps 1000 DataRate'
# → Error: rpn: custom define: metric "Mbps" already exists
-
-gt 'custom define foobar 42 Custom'
-gt 'custom define foobar 99 Custom'
-# → Error: rpn: custom define: metric "foobar" already exists
```
In REPL mode, the second define on the same RPN instance fails:
@@ -372,9 +339,7 @@ gt 'custom rename foobar'
## REPL vs Single-Command Mode
-Custom metric commands behave differently depending on how gt is invoked:
-
-### Single-command mode (`./gt '<expression>'`)
+### Single-command mode (`gt '<expression>'`)
Each invocation creates a fresh process with a clean metric registry. `custom define` confirms the metric was registered but stops evaluation, so subsequent tokens are not processed:
@@ -387,7 +352,7 @@ gt 'custom define foobar 42 Custom 10foobar 5foobar +'
# → defined custom metric "foobar" (factor: 42, category: Custom)
```
-### REPL mode (`./gt` interactively)
+### REPL mode (`gt` interactively)
The RPN engine and metric registry persist across lines. Define metrics first, then use them in subsequent calculations:
@@ -408,7 +373,7 @@ removed custom metric "foobar"
no custom metrics defined
```
-REPL mode is the recommended way to work with custom metrics, as it allows defining, using, and managing metrics in a single session.
+REPL mode is the recommended way to work with custom metrics.
## Summary
diff --git a/docs/fast-power.md b/docs/fast-power.md
index 5d6a981..a00f7a5 100644
--- a/docs/fast-power.md
+++ b/docs/fast-power.md
@@ -112,4 +112,4 @@ The `**` operator **requires** an integer exponent. Use `^` for fractional expon
- **Time complexity**: O(log |n|) where n is the exponent. An exponent of 100 requires only ~7 loop iterations (vs 99 naive multiplications).
- **Space complexity**: O(1) for positive exponents; O(log |n|) stack depth for negative exponents (recursive call).
- The implementation uses `float64` throughout, so results may lose precision for very large exponents (same limitations as any floating-point computation).
-- For the specific case of exponent 0, the function returns 1 immediately without entering the loop.
+- For exponent 0, the function returns 1 immediately without entering the loop.
diff --git a/docs/hyper-operators.md b/docs/hyper-operators.md
index 0953e10..bb05e20 100644
--- a/docs/hyper-operators.md
+++ b/docs/hyper-operators.md
@@ -1,11 +1,8 @@
# Hyper RPN Operators
-Hyper operators operate on **all** values currently on the stack, rather than
-just the top one or two. They pop every value, reduce them left-associatively,
-and push a single result back.
+Hyper operators operate on **all** values currently on the stack, rather than just the top one or two. They pop every value, reduce them left-associatively, and push a single result back.
-The syntax uses square brackets: `[+]`, `[*]`, `[-]`, `[/]`, `[^]`, `[%]`,
-`[lg]`, `[log]`, `[ln]`.
+The syntax uses square brackets: `[+]`, `[*]`, `[-]`, `[/]`, `[^]`, `[%]`, `[lg]`, `[log]`, `[ln]`.
## How Hyper Operators Work
@@ -24,13 +21,11 @@ Input: 1 2 3 4 5 [+]
Result: 15
```
-All five values are consumed, summed left-to-right (`((((1 + 2) + 3) + 4) +
-5)`), and the single result is pushed back.
+All five values are consumed, summed left-to-right (`((((1 + 2) + 3) + 4) + 5)`), and the single result is pushed back.
### Requirements
-- At least **two** values must be on the stack, or the operator returns an
- error.
+- At least **two** values must be on the stack, or the operator returns an error.
- After execution, exactly one value remains on the stack.
## Arithmetic Hyper Operators
@@ -44,8 +39,6 @@ $ gt '1 2 3 4 5 [+]'
15
```
-Equivalently: `1 + 2 + 3 + 4 + 5` = 15.
-
With two operands, behaves identically to binary `+`:
```
@@ -60,11 +53,6 @@ Multiplies all stack values left-associatively. Result is always unitless.
```
$ gt '2 3 4 [*]'
24
-```
-
-Equivalently: `2 * 3 * 4` = 24.
-
-```
$ gt '1 2 3 [*]'
6
```
@@ -76,38 +64,24 @@ Subtracts all stack values left-associatively from the first.
```
$ gt '10 3 2 [-]'
5
-```
-
-Equivalently: `10 - 3 - 2` = 5.
-
-```
$ gt '100 10 20 30 [-]'
40
```
-Equivalently: `100 - 10 - 20 - 30` = 40.
-
### `[/]` Division
-Divides all stack values left-associatively from the first. Result is always
-unitless.
+Divides all stack values left-associatively from the first. Result is always unitless.
```
$ gt '100 5 2 [/]'
10
-```
-
-Equivalently: `100 / 5 / 2` = 10.
-
-```
$ gt '1000 10 10 [/]'
10
```
### `[^]` Power
-Raises left-associatively. The first value is the base, subsequent values are
-successive exponents. Result is always unitless.
+Raises left-associatively. The first value is the base, subsequent values are successive exponents. Result is always unitless.
```
$ gt '2 3 2 [^]'
@@ -139,12 +113,9 @@ $ gt '10 3 2 2 [%]'
0
```
-Equivalently: `((((10 % 3) % 2) % 2)` = `(1 % 2) % 2` = `1 % 2` = 1.
-
## Logarithmic Hyper Operators
-Logarithmic hyper operators compute the **sum** of the log function applied to
-each stack value. All input values must be positive.
+Logarithmic hyper operators compute the **sum** of the log function applied to each stack value. All input values must be positive.
### `[lg]` Base-2 Logarithm Sum
@@ -180,18 +151,15 @@ Equivalently: `ln(2.718281828) + ln(7.389)` ≈ `1 + 2` ≈ 3.
## Metric-Aware Behavior
-Some hyper operators are metric-aware, meaning they understand units and can
-operate on values with compatible units.
+Some hyper operators are metric-aware, meaning they understand units and can operate on values with compatible units.
### Metric-aware operators: `[+]`, `[-]`, `[%]`
These operators:
-1. **Validate** that all operands share the same metric category (or are
- unitless, which is always compatible).
+1. **Validate** that all operands share the same metric category (or are unitless, which is always compatible).
2. **Convert** all values to the result metric's base units before computing.
-3. **Push** the result with the first non-unitless metric (or unitless if all
- inputs are unitless).
+3. **Push** the result with the first non-unitless metric (or unitless if all inputs are unitless).
```
$ gt '1km 2km 3km [+]'
@@ -208,61 +176,34 @@ $ gt '1km 500m [+]'
`500m` is converted to `0.5km`, then `1km + 0.5km = 1.5km`.
```
-$ gt '100m 0.005km [+]'
-105
-```
-
-`0.005km` is converted to `5m`, then `100m + 5m = 105m`.
-
-```
-$ gt '5km 1km 2km [-]'
-2
-```
-
-Result is `5 - 1 - 2 = 2 km`.
-
-```
$ gt '10m 3m 2m [%]'
1
```
`10 % 3 = 1`, then `1 % 2 = 1 m`.
-```
-$ gt '1km 1000m [+]'
-2
-```
-
-`1000m` converts to `1km`, result is `1 + 1 = 2 km`.
-
### Non-metric operators: `[*]`, `[/]`, `[^]`, `[lg]`, `[log]`, `[ln]`
-These operators use raw numeric values and always produce unitless (Cool)
-results, regardless of input units:
+These operators use raw numeric values and always produce unitless (Cool) results, regardless of input units:
-- `[*]` — multiplying meters by meters would yield square meters, a different
- category, so the result is unitless.
+- `[*]` — multiplying meters by meters would yield square meters, a different category, so the result is unitless.
- `[/]` — dividing two like units yields a ratio, which is unitless.
- `[^]` — exponents are inherently unitless.
-- `[lg]`, `[log]`, `[ln]` — logarithms require dimensionless inputs, so the
- raw numeric value is used and the result is unitless.
+- `[lg]`, `[log]`, `[ln]` — logarithms require dimensionless inputs, so the raw numeric value is used and the result is unitless.
### Mixed unitless and unit values
-Unitless (Cool) values can be combined with any metric category — they
-"absorb" and take on the category of the other operands:
+Unitless (Cool) values can be combined with any metric category — they "absorb" and take on the category of the other operands:
```
$ gt '0 5km [+]'
5
```
-## Practical Use Cases
+## Examples
### Batch aggregation
-Sum a series of readings in one command:
-
```
$ gt '12 15 18 14 16 [+]'
75
@@ -270,8 +211,6 @@ $ gt '12 15 18 14 16 [+]'
### Running total with metric conversion
-Sum distances in different units:
-
```
$ gt '5km 2km 1000m [+]'
8
@@ -286,26 +225,6 @@ $ gt '2 5 10 [*]'
100
```
-### Chained reduction with regular operators
-
-Compare hyper `[+]` with chained binary `+`:
-
-```
-$ gt '1 2 3 4 5 +'
- +
- +
- +
- +'
-15
-```
-
-Equivalent (but much shorter) with hyper:
-
-```
-$ gt '1 2 3 4 5 [+]'
-15
-```
-
### Cascading subtraction
```
@@ -363,8 +282,7 @@ Error: ln undefined for non-positive numbers
### Incompatible metrics
-Mixing different metric categories (e.g., length and weight) in a metric-aware
-operator returns an error.
+Mixing different metric categories (e.g., length and weight) in a metric-aware operator returns an error.
### Insufficient operands
diff --git a/docs/log-operators.md b/docs/log-operators.md
index cc13b49..28f017b 100644
--- a/docs/log-operators.md
+++ b/docs/log-operators.md
@@ -1,11 +1,8 @@
# Logarithm RPN Operators
-`gt` provides three logarithm operators: `lg` (base 2), `log` (base 10), and
-`ln` (natural log, base *e*). Each is a unary operator that pops a single value
-from the stack, computes the logarithm, and pushes the result.
+gt provides three logarithm operators: `lg` (base 2), `log` (base 10), and `ln` (natural log, base *e*). Each is a unary operator that pops a single value from the stack, computes the logarithm, and pushes the result.
-Logarithm results are always unitless (Cool metric), regardless of whether the
-input carried a metric.
+Logarithm results are always unitless (Cool metric), regardless of whether the input carried a metric.
## How RPN Works
@@ -28,10 +25,7 @@ Result: 3
Computes the base-2 logarithm: log₂(*x*).
-#### Mathematical explanation
-
-log₂(*x*) = *y* means 2^*y* = *x*. It answers: "To what power must 2 be raised
-to produce *x*?"
+log₂(*x*) = *y* means 2^*y* = *x*. It answers: "To what power must be raised to produce *x*?"
#### Examples
@@ -49,12 +43,10 @@ $ echo "1e-10 lg" | gt
-33.21928095
```
-#### Practical use cases
+#### Use cases
-- **Information theory** — Number of bits needed to represent *x* distinct
- values (e.g., log₂(1024) = 10 bits).
+- **Information theory** — Number of bits needed to represent *x* distinct values (e.g., log₂(1024) = 10 bits).
- **Algorithms** — Time complexity of divide-and-conquer algorithms (O(log n)).
-- **Digital audio** — Bit-depth calculations.
- **Computer science** — Tree height, binary search steps.
---
@@ -63,10 +55,7 @@ $ echo "1e-10 lg" | gt
Computes the base-10 logarithm: log₁₀(*x*).
-#### Mathematical explanation
-
-log₁₀(*x*) = *y* means 10^*y* = *x*. It answers: "To what power must 10 be
-raised to produce *x*?"
+log₁₀(*x*) = *y* means 10^*y* = *x*. It answers: "To what power must 10 be raised to produce *x*?"
#### Examples
@@ -87,15 +76,11 @@ $ echo "1e-10 log" | gt
-10
```
-#### Practical use cases
+#### Use cases
-- **Decibels (dB)** — Sound intensity and signal power ratios:
- L = 10 · log₁₀(P/P₀). Example: `1000 10 / log 10 *` → 30 dB.
-- **pH scale** — Acidity/alkalinity: pH = -log₁₀([H⁺]). Example:
- `1e-7 log 0 -` → 7 (neutral water).
-- **Richter scale** — Earthquake magnitude.
-- **Order of magnitude** — Quick estimate of size: log₁₀(500) ≈ 2.7 means
- "between 100 and 1000".
+- **Decibels (dB)** — Sound intensity and signal power ratios: L = 10 · log₁₀(P/P₀). Example: `1000 10 / log 10 *` → 30 dB.
+- **pH scale** — Acidity/alkalinity: pH = -log₁₀([H⁺]). Example: `1e-7 log 0 -` → 7 (neutral water).
+- **Order of magnitude** — Quick estimate of size: log₁₀(500) ≈ 2.7 means "between 100 and 1000".
- **Scientific notation** — The integer part of log₁₀(*x*) gives the exponent.
---
@@ -104,10 +89,7 @@ $ echo "1e-10 log" | gt
Computes the natural logarithm: ln(*x*) = logₑ(*x*), where *e* ≈ 2.718281828.
-#### Mathematical explanation
-
-ln(*x*) = *y* means *e*^*y* = *x*. It is the inverse of the exponential function
-and the integral of 1/*t* from 1 to *x*.
+ln(*x*) = *y* means *e*^*y* = *x*. It is the inverse of the exponential function and the integral of 1/*t* from 1 to *x*.
#### Examples
@@ -125,21 +107,18 @@ $ echo "7.38905609893065 ln" | gt
2
```
-#### Practical use cases
+#### Use cases
-- **Continuous growth** — Compound interest, population growth:
- A = A₀ · e^(rt). Solve for t: t = ln(A/A₀) / r.
+- **Continuous growth** — Compound interest, population growth: A = A₀ · e^(rt). Solve for t: t = ln(A/A₀) / r.
- **Probability & statistics** — Normal distribution, likelihood functions.
- **Calculus** — Derivative of ln(*x*) is 1/*x*; integral of 1/*x* is ln(|*x*|).
- **Entropy** — Shannon entropy uses natural log in thermodynamics.
-- **Chemistry** — Arrhenius equation for reaction rates.
---
## Edge Cases
-All three operators are **undefined for non-positive numbers**. Zero and negative
-inputs produce an error:
+All three operators are **undefined for non-positive numbers**. Zero and negative inputs produce an error:
```
$ echo "0 lg" | gt
@@ -169,24 +148,10 @@ Error: ln undefined for non-positive numbers
## Metric Handling
-Logarithms always produce unitless results. Even when the input carries a metric,
-the result is Cool (no metric):
+Logarithms always produce unitless results. Even when the input carries a metric, the result is Cool (no metric):
```
$ echo "100Mbps lg" | gt # treats as number with metric, result is Cool
```
-This is mathematically correct — taking a logarithm of a dimensioned quantity
-requires a reference value (e.g., log₁₀(P/P₀) for decibels), so gt treats the
-operands as their numeric values.
-
----
-
-## Implementation
-
-- Source: `internal/rpn/operations_arithmetic.go` — `Log2`, `Log10`, `Ln`
-- Uses `math.Log2`, `math.Log10`, `math.Log` from Go's standard library
-- Shared helper: `logOp(stack, opName, logFn)` handles pop, validate, compute,
- and push
-- Tests: `internal/rpn/operations_test.go` — `TestLog2`, `TestLog10`, `TestLn`
- plus boolean coercion and hyper-operator variants
+This is mathematically correct — taking a logarithm of a dimensioned quantity requires a reference value (e.g., log₁₀(P/P₀) for decibels), so gt treats the operands as their numeric values.
diff --git a/docs/metric-commands.md b/docs/metric-commands.md
index 8c0c126..5356dbd 100644
--- a/docs/metric-commands.md
+++ b/docs/metric-commands.md
@@ -2,7 +2,7 @@
The `metric` command provides runtime introspection and configuration for gt's metrics system. It lets you inspect metric metadata, explore available categories and units, check compatibility between values, and switch between SI and IEC prefix modes.
-All metric commands are RPN operators — they work on the stack, consume tokens, and produce string output. They can be used in single-command mode (`./gt '<expression>'`) or interactively in REPL mode (`./gt`).
+All metric commands are RPN operators — they work on the stack, consume tokens, and produce string output. They work in single-command mode (`gt '<expression>'`) or interactively in REPL mode (`gt`).
## `metric show`
@@ -48,7 +48,7 @@ Cool (Universal)
kmh, Speed, base: m/s, factor: 0.2777777778
```
-Note that `metric show` does not consume the value from the stack — it only peeks at the top.
+`metric show` does not consume the value from the stack — it only peeks at the top.
## `metric list`
@@ -59,8 +59,6 @@ gt 'metric list'
# → DataRate, DataSize, Distance, Speed, Time, Universal, Weight
```
-This is useful for discovering what categories exist before drilling down with the category subcommand.
-
## `metric <category>`
Lists all metric names within a given category. The category name is case-sensitive and must match exactly (e.g., `DataRate`, not `datarate` or `data-rate`).
@@ -92,8 +90,6 @@ gt 'metric Temperature'
# → Error: rpn: metric Temperature: metric: unknown category "Temperature"
```
-This subcommand is a good way to discover available units within a category, especially for DataSize which has both SI and IEC variants.
-
## `metric compatible`
Checks whether the top two values on the stack have compatible metric categories. Pops nothing from the stack — it only inspects. Pushes a descriptive string result.
@@ -175,9 +171,7 @@ The prefix mode only affects SI-prefixed data size units (KB, MB, GB, TB, PB). A
## REPL vs Single-Command Mode
-The `metric` commands behave differently depending on how gt is invoked:
-
-### Single-command mode (`./gt '<expression>'`)
+### Single-command mode (`gt '<expression>'`)
A fresh RPN engine is created for each invocation. State changes like `metric binary set` only apply to that single expression and are discarded afterward:
@@ -193,7 +187,7 @@ gt '1GB @MB convert'
Note: In single-command mode, `metric binary set` and subsequent tokens in the same expression may not all execute — metric commands return immediately after handling their tokens. Use REPL mode for mode changes followed by calculations.
-### REPL mode (`./gt` interactively)
+### REPL mode (`gt` interactively)
The RPN engine persists across lines, so prefix mode changes remain in effect:
@@ -234,7 +228,7 @@ gt '1KiB @bytes convert' # Always 1024
- **IEC mode**: Matches operating system memory reporting. Use when you need 1 GB = 1,024 MB.
- **IEC units** (KiB/MiB/GiB): Always unambiguous — use these in scripts or documentation where precision matters.
-## Practical Use Cases
+## Examples
### Exploring the metrics system
diff --git a/docs/metrics.md b/docs/metrics.md
index 4ae2732..ebadaec 100644
--- a/docs/metrics.md
+++ b/docs/metrics.md
@@ -148,7 +148,7 @@ prefix mode: IEC
In single-command mode, SI is always used.
-## Practical Use Cases
+## Examples
### Bandwidth Planning
diff --git a/docs/percentage-calculations.md b/docs/percentage-calculations.md
index 5a6a722..1702d04 100644
--- a/docs/percentage-calculations.md
+++ b/docs/percentage-calculations.md
@@ -1,7 +1,6 @@
# Percentage Calculations
-`gt` supports three forms of percentage calculation, each solving a different
-unknown. All inputs are case-insensitive and support decimal numbers.
+gt supports three forms of percentage calculation, each solving a different unknown. All inputs are case-insensitive and support decimal numbers.
## Syntax
@@ -46,10 +45,6 @@ gt '20% of 150'
gt '50% of 200'
# 50.00% of 200.00 = 100.00
# Steps: (50.00 / 100) * 200.00 = 0.50 * 200.00 = 100.00
-
-gt 'what is 20% of 150'
-# 20.00% of 150.00 = 30.00
-# Steps: (20.00 / 100) * 150.00 = 0.20 * 150.00 = 30.00
```
### Form 2: X is what % of Y
@@ -62,10 +57,6 @@ gt '30 is what % of 150'
gt '75 is what % of 300'
# 75.00 is 25.00% of 300.00
# Steps: (75.00 / 300.00) * 100 = 0.25 * 100 = 25.00%
-
-gt '3.75 is what % of 150'
-# 3.75 is 2.50% of 150.00
-# Steps: (3.75 / 150.00) * 100 = 0.03 * 100 = 2.50%
```
### Form 3: X is Y% of what
@@ -78,10 +69,6 @@ gt '30 is 20% of what'
gt '50 is 25% of what'
# 50.00 is 25.00% of 200.00
# Steps: (50.00 / 25.00) * 100 = 2.00 * 100 = 200.00
-
-gt '3.75 is 2.5% of what'
-# 3.75 is 2.50% of 150.00
-# Steps: (3.75 / 2.50) * 100 = 1.50 * 100 = 150.00
```
## Output Format
@@ -97,10 +84,9 @@ Every percentage calculation returns two lines:
| X is what % of Y | `X.00 is P.00% of Y.00` |
| X is Y% of what | `X.00 is Y.00% of Whole.00` |
-The steps line shows the formula used, intermediate values, and the final
-result so you can verify the math.
+The steps line shows the formula used, intermediate values, and the final result so you can verify the math.
-## Practical Use Cases
+## Examples
### Discounts
@@ -156,8 +142,6 @@ gt '0% of 150'
# 0.00% of 150.00 = 0.00
```
-Zero percent of any number is always zero.
-
### Percentages over 100%
```bash
@@ -168,9 +152,6 @@ gt '200% of 50'
# 200.00% of 50.00 = 100.00
```
-Percentages over 100% are fully supported and produce values greater than
-the base.
-
### Decimal values
```bash
@@ -181,8 +162,6 @@ gt '3.75 is what % of 150'
# 3.75 is 2.50% of 150.00
```
-All three forms accept decimal numbers for both the percentage and the values.
-
### Large numbers
```bash
@@ -190,8 +169,6 @@ gt '15% of 1000000'
# 15.00% of 1000000.00 = 150000.00
```
-Calculations handle large numbers without issue.
-
### Case insensitivity
```bash
@@ -200,8 +177,6 @@ gt '30 IS WHAT % OF 150'
gt '30 IS 20% OF WHAT'
```
-All keyword matching is case-insensitive.
-
### Whitespace flexibility
```bash
@@ -209,28 +184,17 @@ gt '20 % of 150'
gt '30 is what% of 150'
```
-Extra whitespace is tolerated. Spaces around the `%` sign are optional in
-forms 2 and 3.
-
### Not supported
-- **Negative numbers** — `-20% of 150` is not recognized; only non-negative
- numbers are accepted
-- **Division by zero** — `30 is what % of 0` and `30 is 0% of what` both
- produce an error since they require dividing by zero
+- **Negative numbers** — `-20% of 150` is not recognized; only non-negative numbers are accepted
+- **Division by zero** — `30 is what % of 0` and `30 is 0% of what` both produce an error since they require dividing by zero
## Known Limitations
-1. **No negative numbers** — The regex patterns only match non-negative
- numeric values (`\d+(?:\.\d+)?`). Expressions like `-20% of 150` will not
- be recognized as percentage calculations.
+1. **No negative numbers** — The regex patterns only match non-negative numeric values (`\d+(?:\.\d+)?`). Expressions like `-20% of 150` will not be recognized as percentage calculations.
-2. **Single-line input** — Percentage calculations are single-command
- operations; they do not interact with the RPN stack.
+2. **Single-line input** — Percentage calculations are single-command operations; they do not interact with the RPN stack.
-3. **No chained operations** — You cannot combine percentage calculations
- with RPN in a single expression. Use RPN for the arithmetic after
- getting the percentage result.
+3. **No chained operations** — You cannot combine percentage calculations with RPN in a single expression. Use RPN for the arithmetic after getting the percentage result.
-4. **Zero percent with "of what"** — `X is 0% of what` is mathematically
- undefined and returns a division-by-zero error.
+4. **Zero percent with "of what"** — `X is 0% of what` is mathematically undefined and returns a division-by-zero error.
diff --git a/docs/repl-mode.md b/docs/repl-mode.md
index b89b5a4..8f9dd7c 100644
--- a/docs/repl-mode.md
+++ b/docs/repl-mode.md
@@ -328,7 +328,7 @@ Five methods exit the REPL:
Ctrl+C does not exit by default — it gives you a chance to cancel. Press Ctrl+D or type `quit` to leave.
-## Practical Workflow Examples
+## Examples
### Multi-step RPN calculation
diff --git a/docs/stack-operations.md b/docs/stack-operations.md
index dbc3683..dd545aa 100644
--- a/docs/stack-operations.md
+++ b/docs/stack-operations.md
@@ -1,14 +1,10 @@
# Stack Manipulation Operators
-`gt` provides a set of operators for directly manipulating the RPN stack. These
-let you duplicate values, reorder elements, discard items, inspect the stack,
-and clear everything.
+gt provides operators for directly manipulating the RPN stack. These let you duplicate values, reorder elements, discard items, inspect the stack, and clear everything.
## How the Stack Works
-The RPN stack grows from bottom to top. The **top** of the stack is the most
-recently pushed value. Stack manipulation operators read and modify this
-structure without performing arithmetic.
+The RPN stack grows from bottom to top. The **top** of the stack is the most recently pushed value. Stack manipulation operators read and modify this structure without performing arithmetic.
```
Stack (bottom -> top):
@@ -40,8 +36,7 @@ Stack (bottom -> top):
## `dup` — Duplicate Top Value
-Pushes a copy of the top stack value onto the stack. Requires at least one
-value on the stack.
+Pushes a copy of the top stack value onto the stack. Requires at least one value on the stack.
### Stack visualization
@@ -77,8 +72,7 @@ $ gt '7 dup dup +'
7 14
```
-Step by step: `7` pushed, `dup` produces `[7, 7]`, `dup` produces `[7, 7, 7]`,
-`+` pops the top two producing `[7, 14]`.
+Step by step: `7` pushed, `dup` produces `[7, 7]`, `dup` produces `[7, 7, 7]`, `+` pops the top two producing `[7, 14]`.
### Practical use cases
@@ -89,9 +83,7 @@ $ gt '10 dup 5 gt'
true
```
-Checks if `10 > 5` while keeping the original `10` available (the comparison
-pops both values, but `dup` ensures the original is preserved before the
-operation).
+Checks if `10 > 5` while keeping the original `10` available (the comparison pops both values, but `dup` ensures the original is preserved before the operation).
**Reuse without re-entry** — avoid typing the same value multiple times:
@@ -106,8 +98,7 @@ Computes `2*pi` and `4*pi` from a single entry of pi.
## `swap` — Swap Top Two Values
-Exchanges the positions of the top two stack values. Requires at least two
-values on the stack.
+Exchanges the positions of the top two stack values. Requires at least two values on the stack.
### Stack visualization
@@ -148,13 +139,11 @@ $ gt '3 4 5 swap -'
3 1
```
-Step by step: `3` pushed `[3]`, `4` pushed `[3, 4]`, `5` pushed `[3, 4, 5]`,
-`swap` swaps top two `[3, 5, 4]`, `-` pops 5 and 4 pushing 1 `[3, 1]`.
+Step by step: `3` pushed `[3]`, `4` pushed `[3, 4]`, `5` pushed `[3, 4, 5]`, `swap` swaps top two `[3, 5, 4]`, `-` pops 5 and 4 pushing 1 `[3, 1]`.
### Practical use cases
-**Correct operand order** — when the natural reading order differs from RPN
-order:
+**Correct operand order** — when the natural reading order differs from RPN order:
```
$ gt '100 1 swap /'
@@ -170,15 +159,13 @@ $ gt '4 3 swap ^'
81
```
-Computes `3^4` = 81 (swap turns `[4, 3]` into `[3, 4]`, then `^` computes
-`3^4`).
+Computes `3^4` = 81 (swap turns `[4, 3]` into `[3, 4]`, then `^` computes `3^4`).
---
## `pop` — Discard Top Value
-Removes and discards the top stack value. Requires at least one value on the
-stack.
+Removes and discards the top stack value. Requires at least one value on the stack.
### Stack visualization
@@ -208,8 +195,7 @@ $ gt '10 20 + 30 pop'
30
```
-Step by step: `10` pushed, `20` pushed, `+` produces `[30]`, `30` pushed
-`[30, 30]`, `pop` discards top `[30]`.
+Step by step: `10` pushed, `20` pushed, `+` produces `[30]`, `30` pushed `[30, 30]`, `pop` discards top `[30]`.
### Practical use cases
@@ -231,8 +217,7 @@ $ gt '100 200 pop'
## `show` / `showstack` / `print` — Display the Stack
-Prints all values currently on the stack without modifying it. All three are
-equivalent. Requires no operands.
+Prints all values currently on the stack without modifying it. All three are equivalent. Requires no operands.
### Stack visualization
@@ -301,8 +286,7 @@ Displays `10` (the result of `100 / 10`) before adding 5.
## `clear` — Reset Variables and Constants
-Clears all user-defined variables and constants from the session. This affects
-the variable table, not the RPN stack directly.
+Clears all user-defined variables and constants from the session. This affects the variable table, not the RPN stack directly.
### Examples
@@ -313,15 +297,6 @@ $ gt 'clear'
All variables cleared
```
-### Practical use cases
-
-**Clean slate** — reset a session after defining many temporary variables:
-
-```
-$ gt 'clear'
-All variables cleared
-```
-
---
## Error Handling
@@ -357,8 +332,7 @@ $ gt '5 dup dup + *'
75
```
-Step by step: `[5]` -> `dup` -> `[5, 5]` -> `dup` -> `[5, 5, 5]` -> `+` ->
-`[5, 10]` -> `*` -> `[50]`. This computes `5 * (5 + 5)` = 50.
+Step by step: `[5]` -> `dup` -> `[5, 5]` -> `dup` -> `[5, 5, 5]` -> `+` -> `[5, 10]` -> `*` -> `[50]`. This computes `5 * (5 + 5)` = 50.
### Swap-based reordering in complex expressions
@@ -367,8 +341,7 @@ $ gt '2 3 4 swap ^ -'
-62
```
-Step by step: `[2]` -> `[2, 3]` -> `[2, 3, 4]` -> `swap` -> `[2, 4, 3]` ->
-`^` -> `[2, 4^3]` = `[2, 64]` -> `-` -> `[2 - 64]` = `[-62]`.
+Step by step: `[2]` -> `[2, 3]` -> `[2, 3, 4]` -> `swap` -> `[2, 4, 3]` -> `^` -> `[2, 4^3]` = `[2, 64]` -> `-` -> `[2 - 64]` = `[-62]`.
### Show the intermediate state
@@ -376,5 +349,4 @@ Step by step: `[2]` -> `[2, 3]` -> `[2, 3, 4]` -> `swap` -> `[2, 4, 3]` ->
$ gt '10 20 30 + show 5 *'
```
-This pushes 10, 20, 30, adds top two (50), shows the stack `[10, 50]`, then
-multiplies to get `500`.
+This pushes 10, 20, 30, adds top two (50), shows the stack `[10, 50]`, then multiplies to get `500`.
diff --git a/docs/symbols.md b/docs/symbols.md
index 77840ce..df961a5 100644
--- a/docs/symbols.md
+++ b/docs/symbols.md
@@ -146,7 +146,7 @@ Stack operators that work on any `StackValue` work with symbols:
:x pop → error: empty result: expression evaluated to nothing
```
-## Practical Use Cases
+## Examples
### Explicit Variable Assignment
@@ -198,10 +198,3 @@ vars → No variables defined
| `:x 1 +` | value ":x" is not numeric | Symbols can't be used in arithmetic |
| `:x d` | variable not found: x | Variable x not defined |
| `:x pop` | empty result: expression evaluated to nothing | Stack empty after pop |
-
-## Reference
-
-- **Type**: `internal/rpn/number.go` — `Symbol` struct and `NewSymbol()`
-- **Parsing**: `internal/rpn/rpn_parse.go` — `checkAndPushSymbol()`, `dispatchOperator()`
-- **Assignment**: `internal/rpn/operations_variables.go` — `AssignLeft()`, `AssignRight()` (both accept `*Symbol` as the name argument)
-- **Deletion**: `internal/rpn/operations_variables.go` — `DeleteVariable()` (called via the `d` operator, expects `*Symbol` or `*StringNum`)
diff --git a/docs/unit-conversion.md b/docs/unit-conversion.md
index b75401c..df9ddf0 100644
--- a/docs/unit-conversion.md
+++ b/docs/unit-conversion.md
@@ -173,83 +173,53 @@ gt '100kmh 1hr * @mi convert' # → 62.13711922
gt '1Gbps 1hr * @GB convert' # → 450
```
-## Practical Use Cases
+## Examples
### Network Bandwidth
```bash
-# Convert internet speed to familiar units
gt '500Mbps @Gbps convert' # → 0.5
-
-# Calculate how many GB you download in an hour at 1 Gbps
gt '1Gbps 1hr * @GB convert' # → 450
-
-# Server throughput in Mbps
gt '100Kbps @Mbps convert' # → 0.1
```
### Travel Planning
```bash
-# Speed limit conversion (US to metric)
gt '65mph @kmh convert' # → 104.86
-
-# Distance conversion for flight planning
gt '100nm @km convert' # → 185.2 (nautical miles to km)
-
-# Flight time: 500 miles at 400 mph
gt '500mi 400mph / @min convert' # → 75 minutes
-
-# Speed of sound in km/h
gt '340mps @kmh convert' # → 1224
```
### Weight Conversions
```bash
-# Body weight
gt '70kg @lb convert' # → 154.32
-
-# Shipping: 50 oz to grams
gt '50oz @g convert' # → 1417.476156
-
-# Industrial weight
gt '2.5ton @kg convert' # → 2500
```
### Cooking and Recipes
```bash
-# Kitchen weight
gt '250g @oz convert' # → 8.82
-
-# Small measurements
gt '500mg @g convert' # → 0.5
```
### Data Storage
```bash
-# Disk space: how many GB in a TB
gt '1TB @GB convert' # → 1000
-
-# RAM: how many MiB in a GiB
gt '1GiB @MiB convert' # → 1024
-
-# File size: 500 MB in KB
gt '500MB @KB convert' # → 500000
```
### Time Planning
```bash
-# How many seconds in 3 days
gt '3day @s convert' # → 259200
-
-# Half-hour delay in milliseconds
gt '0.5hr @ms convert' # → 1800000
-
-# Milliseconds to seconds
gt '2500ms @s convert' # → 2.5
```
@@ -257,7 +227,7 @@ gt '2500ms @s convert' # → 2.5
### Incompatible Categories
-Converting between different metric categories produces an error because the units are fundamentally incompatible:
+Converting between different metric categories produces an error:
```bash
gt '1km @hr convert' # Error: incompatible metrics (Distance vs Time)
diff --git a/docs/variables.md b/docs/variables.md
index 60474cc..b34ef9c 100644
--- a/docs/variables.md
+++ b/docs/variables.md
@@ -134,7 +134,7 @@ The `=` operator supports evaluating an expression immediately after assignment:
x 10 = x 5 + → 15 (assigns x=10, then computes x+5)
```
-## Practical Use Cases
+## Examples
### Storing Reusable Values
@@ -167,10 +167,3 @@ sum 10 + → 10
sum 20 + → 30
sum 5 - → 25
```
-
-## Reference
-
-- **Implementation**: `internal/rpn/operations_variables.go` (assignment operators, variable CRUD)
-- **Parsing**: `internal/rpn/rpn_parse.go` (`handleAssignmentOp()`, `handleStandardAssign()`)
-- **Registry**: `internal/rpn/operator_registry.go` (operator registration for `:=`, `=:`, `=`, `d`)
-- **Variable store**: `internal/rpn/variables.go` (thread-safe variable storage with save/load)