A GUI calculator built with C++17 and Qt6 that supports arbitrary-precision rational number arithmetic. It utilizes a custom BigInt class (linked-list-based arbitrary precision integer) and a Rational class built on top of it for exact fraction arithmetic with no precision loss.
- Arbitrary-precision integer: Linked list (
DigitNode) storage, theoretically limited only by memory - Exact rational arithmetic: Always stored and computed as fractions, automatically reduced
- Multiple input formats: Integers, decimals, fractions (
a/b), and scientific notation - Dual display: Results shown as both fractions and decimals
- Modern Qt GUI: Fusion style, clean layout, friendly interaction
├── main.cpp # Entry point
├── CalculatorWidget.h # Calculator UI header
├── CalculatorWidget.cpp # Calculator UI implementation
├── Storage.h # Linked list node + BigInteger/BigRational (reference)
├── BigInt.h # Arbitrary-precision integer (header-only)
├── Rational.h # Rational number class (header-only)
├── CMakeLists.txt # CMake build configuration
└── PLAN.md # Development plan
- CMake ≥ 3.16
- C++17 compatible compiler (GCC, Clang, MSVC)
- Qt 6 (Core + Widgets modules)
cd ArbitraryRationalCalculator
mkdir build && cd build
cmake ..
cmake --build .
./ArbitraryRationalCalculatorWindows Users: Make sure Qt6 is in your system
PATH, or use Visual Studio's CMake integration.macOS Users: If Qt6 is installed via Homebrew, use
cmake .. -DCMAKE_PREFIX_PATH=$(brew --prefix qt6).
| Format | Example | Description |
|---|---|---|
| Integer | 12345678901234567890 |
Arbitrary length integer |
| Decimal | 3.14159265358979323846 |
Arbitrary precision decimal, auto-converted to fraction |
| Fraction | 1/2 |
Numerator/Denominator, auto-reduced |
| Scientific | 1.23e-5 |
Supports positive and negative exponents |
Notes: Denominator must not be zero; divisor must not be zero for division; whitespace is automatically ignored.
The BigInt class uses a little-endian linked list to store each digit (0–9). Each DigitNode holds one digit and a pointer to the next higher digit.
- Base unit:
BASE = 1e9(stores 9 decimal digits per element into_vec()) - Core algorithms:
- Addition / Subtraction: column addition/subtraction on vector representation
- Multiplication: double loop column multiplication
- Division: binary search trial quotient method
normalize(): auto-reduction using Euclidean algorithm (GCD)
- Operator overloads: Full set of comparison, arithmetic, and compound assignment operators
The Rational class builds upon BigInt to represent rational numbers exactly as numerator/denominator fractions. Automatically reduced on construction, results always simplified, supports decimal conversion via toDecimalString(int precision).
Two QLineEdit widgets for operands, QComboBox for operator selection, results displayed as both fraction and decimal, custom stylesheet.
- Applications requiring exact large integer and fraction arithmetic
- Educational demonstrations of big number algorithms, fraction arithmetic, and Qt GUI programming
- Any calculation exceeding the limits of native C++ integer types (e.g.,
int64_t)