A sophisticated command-line utility converting miles to kilometers using the mathematical properties of the Fibonacci sequence and the golden ratio.
An educational demonstration of mathematical concepts applied to practical computation problems
The project leverages the proximity between the golden ratio (φ ≈ 1.618034) and the exact miles-to-kilometers conversion factor (1.609344).
Relative error: ~0.54%
Three distinct implementations explore computational strategies: iterative Fibonacci with interpolation, cached Fibonacci conversion, and golden ratio conversion.
O(1) to O(log φ(n)) complexity
Built with C for performance and low-level control, with careful attention to error handling, integer overflow protection, and floating-point precision.
POSIX-style CLI parser
Connecting abstract mathematics to practical computation
Three distinct approaches with unique computational characteristics
Compute Fibonacci pairs until current mile value exceeds input
Locate the Fibonacci pair bracketing the input value
Calculate the proportional distance between Fibonacci points
Dynamically computes Fibonacci numbers until bracketing the input value. Uses 64-bit integers for precision with overflow protection.
Time: O(log φ(miles)) | Space: O(1)
Key Insight: As n increases, the ratio Fn+1/Fn approaches φ, enabling approximation.
Precomputes Fibonacci numbers up to F₉₃ (max before 64-bit overflow). Uses static cache for single initialization with constant-time lookup.
Time: O(1) | Space: O(94)
Optimization: Cache is initialized on first function call, minimizing startup overhead.
Direct implementation of Binet's closed-form formula. Uses logarithmic calculation to find Fibonacci index with floating-point precision.
Time: O(1) | Space: O(1)
Precision Note: Double precision maintains accuracy until ~F₇₀ (1e14 miles).
POSIX-style option processing with conflict detection and validation
The command parser implements a robust POSIX-style option processing system with:
Comprehensive checks include:
Algorithm selection tradeoffs for different use cases
| Method | Time Complexity | Space Complexity | Max Input (miles) | Precision | Use Case |
|---|---|---|---|---|---|
| Basic | O(1) | O(1) | ∞ | Exact | General purpose |
| Interpolation | O(log φ(n)) | O(1) | F₉₂ ≈ 7.5e19 | ~0.54% error | Mathematical demonstration |
| Cached | O(1) | O(94) | F₉₂ ≈ 7.5e19 | ~0.54% error | Repeated conversions |
| Golden Ratio | O(1) | O(1) | ∞ | Degrades with n | Large values (> F₉₂) |