Advanced modular calculator
Project description
๐งฎ Advanced Modular Calculator
A robust, enterprise-grade console-based Python calculator featuring modular architecture, comprehensive unit conversions, and extensive mathematical functions. Built with clean code principles, domain-driven design, and test-driven development.
๐ Features Overview
๐ Standard Calculator
- Expression Evaluation: Evaluates complex arithmetic expressions with full operator precedence
- Persistent History: All calculations are saved with file-based storage
- Error Resilience: Gracefully handles division by zero, syntax errors, and malformed input
- Smart Formatting: Removes trailing zeros and floating-point artifacts
๐ฌ Scientific Calculator
- 24 Engineering Functions: Complete suite of trigonometric, inverse trigonometric, hyperbolic, and inverse hyperbolic functions
- Domain Validation: Explicit mathematical domain checks prevent undefined results
- High Precision: Results formatted to 9 significant figures with intelligent rounding
- O(1) Dispatch: Dictionary-based function lookup using tuple-key mapping for optimal performance
๐ Unit Converter
Comprehensive conversion system supporting 5 categories:
๐ Angle Conversion
- Degrees, Radians, Gradians
- Bidirectional conversions
๐ก๏ธ Temperature Conversion
- Celsius, Kelvin, Fahrenheit
- Full bidirectional support
โ๏ธ Weight Conversion
- 13 Units: Kilogram, Gram, Milligram, Centigram, Decigram, Decagram, Hectogram, Metric Tonne, Ounce, Pound, Stone, Short Ton (US), Long Ton (UK)
- 182 Conversion Pairs: Universal converter handles all unit combinations
- Metric and Imperial systems
๐จ Pressure Conversion
- 6 Units: Atmosphere, Bar, Kilopascal, mmHg, Pascal, PSI
- 30 Conversion Pairs: Medical, meteorological, and engineering standards
- Commonly used in weather, diving, automotive, and industrial applications
๐พ Data Conversion
- 35 Units: Bits, Bytes, Nibbles, KB/KiB, MB/MiB, GB/GiB, TB/TiB, PB/PiB, EB/EiB, ZB/ZiB, YB/YiB
- 1,190 Conversion Pairs: Covers both decimal (SI) and binary (IEC) standards
- Understand the difference between GB (1000ยณ) and GiB (1024ยณ)
- Perfect for computer science, networking, and data storage calculations
๐ฏ Key Technical Highlights
Architecture
- Modular Design: Clear separation of concerns (standard, scientific, converters)
- Package Structure: Proper
calculator/package with focused submodules - Zero Dependencies: Pure Python implementation (except testing)
Mathematical Correctness
- Domain Guarding: Every function validates input domains
sinโปยน(x)โ valid only for -1 โค x โค 1sec(x)โ undefined at 90ยฐ + nยท180ยฐcoth(x)โ undefined at x = 0
- Precision Handling: Deterministic formatting with no floating-point junk
- Error Messages: Clear, human-readable feedback instead of crashes
Performance
- O(1) Function Dispatch: Tuple-key dictionary mapping eliminates long if-else chains
- Universal Converters: Single function handles all unit pairs efficiently
- Minimal Overhead: Direct mathematical operations with no unnecessary abstraction
Code Quality
- Type Hints: Full type annotations throughout codebase
- Docstrings: Comprehensive documentation for all public functions
- Consistent Style: PEP 8 compliant with standardized formatting
- Error Handling: Defensive programming with graceful degradation
๐ Project Structure
Calculator/
โ
โโโ main.py # Compatibility entry point
โโโ std.py # Compatibility shim
โโโ sci.py # Compatibility shim
โโโ converters.py # Compatibility shim
โโโ setup.py # Installable package metadata
โโโ requirements.txt # Runtime dependencies (none)
โโโ requirements-dev.txt # Dev tools (pytest, ruff, mypy, etc.)
โโโ history/ # Calculator history files (ignored in git)
โ
โโโ calculator/ # Primary package
โ โโโ __init__.py
โ โโโ main.py # Application entry point
โ โโโ standard.py # Standard arithmetic engine
โ โโโ scientific.py # Scientific functions engine
โ โโโ router.py # Unit converter router
โ โโโ config.py # Central configuration
โ โโโ exceptions.py # Custom exceptions
โ โโโ converters/ # Converter modules
โ โโโ __init__.py
โ โโโ base.py # Base converter class
โ โโโ utils.py # Shared converter utilities
โ โโโ angle.py # Angle conversions
โ โโโ temperature.py # Temperature conversions
โ โโโ weight.py # Weight conversions
โ โโโ pressure.py # Pressure conversions
โ โโโ data.py # Data unit conversions (35 units)
โ
โโโ tests/ # Comprehensive test suite
โโโ test_std.py # Standard calculator tests (68 tests)
โโโ test_sci.py # Scientific calculator tests (87 tests)
โโโ test_conveter/ # Converter tests (171 tests)
โโโ test_angle.py
โโโ test_temperature.py
โโโ test_weight.py
โโโ test_pressure.py
๐ Installation & Usage
Prerequisites
- Python 3.10 or higher
- No external dependencies for running the calculator
- pytest required for running tests (optional)
Quick Start
-
Clone the repository:
git clone https://github.com/AryanSolanke/Calculator.git cd Calculator
-
Run the calculator:
python main.pyOr:
python -m calculator.main
-
Run tests (optional):
python -m pytest -v
Usage Examples
Standard Calculator
โค Enter expression (e.g., 2+3*4): (2 + 3) * 5 / (7 - 2)
โ
Result: 5
Scientific Calculator
โค Enter operation number: 1
โค Enter sub-operation number: 1
๐ Enter angle in degrees: 30
โ
Result: sin(30ยฐ) = 0.5
Unit Converter - Data Conversion
๐พ DATA UNIT CONVERSION
โค Enter FROM unit (1-35): 24
โค Enter TO unit (1-35): 25
๐พ Enter data amount: 500
โ
CONVERSION RESULT:
500.0 GB = 465.66 GiB
(Gigabyte โ Gibibyte)
๐งช Testing
The project includes 326 comprehensive tests covering:
- โ Normal operations and edge cases
- โ Domain violations and error handling
- โ Boundary values and extreme inputs
- โ Round-trip conversion accuracy
- โ Symmetry and mathematical properties
Test Coverage
- Standard Calculator: Expression evaluation, history management, error handling
- Scientific Calculator: All 24 functions across all quadrants, domain validation
- Converters: Accuracy verification, bidirectional consistency, unit validation
Running Tests
# Run all tests
python -m pytest -v
# Run specific test file
python -m pytest tests/test_std.py -v
# Run with coverage
pytest tests/ --cov=. --cov-report=html
๐ง Technical Details
Converter Capabilities
Data Converter - Understanding SI vs IEC Standards
Why does my 500 GB hard drive show only 465 GB?
-
Hard Drive Label: 500 GB (Decimal/SI)
- Uses base 1000: 500,000,000,000 bytes
-
Operating System: Shows 465.66 GiB (Binary/IEC)
- Uses base 1024: 500,000,000,000 รท 1,073,741,824 = 465.66 GiB
No space is missing - just different measurement systems!
The data converter handles:
- Decimal units (SI): KB, MB, GB, TB, PB, EB, ZB, YB (powers of 1000)
- Binary units (IEC): KiB, MiB, GiB, TiB, PiB, EiB, ZiB, YiB (powers of 1024)
๐ Learning Outcomes
This project demonstrates:
- โ Clean modular software architecture
- โ Defensive programming for mathematical systems
- โ Domain-driven design principles
- โ Test-driven development methodology
- โ Package organization and import management
- โ User experience design with clear feedback
- โ Performance optimization through algorithmic design
๐ ๏ธ Technology Stack
- Language: Python 3.10+
- Standard Library: math, pathlib, enum, typing
- Testing: pytest framework
- Architecture: Modular, function-dispatch based
- Code Style: PEP 8 compliant
๐ Recent Updates
Version 2.2 - Package Reorganization (Current)
- โ
Proper Package Layout: Introduced
calculator/package with clear module boundaries - โ
Central Config: History files and precision settings consolidated in
calculator/config.py - โ
Base Converter: Shared converter behavior in
calculator/converters/base.py - โ
Compatibility Shims: Root-level
main.py,std.py,sci.py,converters.pypreserved for backward compatibility - โ
History Directory: History files stored under
history/at repo root
Version 2.0 - Major Refactor
- โ Modular Converter Architecture: Separated converters into independent modules
- โ Enhanced User Interface: Added emojis and improved formatting for better UX
- โ Standardized Documentation: Consistent docstrings and comments across all modules
- โ Import System Overhaul: Resolved all import conflicts with proper package structure
- โ Expanded Unit Support: Added pressure conversions (6 units, 30 conversion pairs)
- โ Code Quality: Standardized commenting style, improved error messages
- โ Test Coverage: All 392 tests passing with comprehensive edge case coverage
๐ Code Quality Standards
Docstring Format
def function_name(param: type) -> return_type:
"""
Brief description of function purpose.
Detailed explanation of behavior and any important notes.
Args:
param: Description of parameter
Returns:
Description of return value
Raises:
ErrorType: When this error occurs
"""
Error Handling Pattern
try:
# Main operation
result = operation()
except SpecificError:
# Handle specific error
errmsg()
except Exception:
# Fallback handler
errmsg()
๐ค Contributing
Contributions are welcome! Please ensure:
- All tests pass before submitting PR
- New features include corresponding tests
- Code follows PEP 8 style guide
- Docstrings are provided for all functions
- No external dependencies added without discussion
๐ License
This project is available for educational and personal use.
๐ Acknowledgments
Built with rigorous attention to mathematical correctness, code quality, and user experience. This project serves as a comprehensive example of professional Python development practices.
Built with precision, tested with rigor, designed with care. ๐ฏ
Total Conversion Capabilities: 1,440 unique conversions across 5 categories!
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file aryan_advanced_calculator-1.2.1.tar.gz.
File metadata
- Download URL: aryan_advanced_calculator-1.2.1.tar.gz
- Upload date:
- Size: 39.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
28f279512baab418f5edefbe4af524d9627b25b75a3266e4e1e25d815daf1f74
|
|
| MD5 |
0230a9c7b389a9a89512d3ba766aea80
|
|
| BLAKE2b-256 |
bc51d8b8209ad810f540e65268d8c5944f3b7de5f416fe0a2bc006d300c9b09f
|
File details
Details for the file aryan_advanced_calculator-1.2.1-py3-none-any.whl.
File metadata
- Download URL: aryan_advanced_calculator-1.2.1-py3-none-any.whl
- Upload date:
- Size: 47.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e84648cca8a7ab4be24b81d53624a4c98c65ec6803fa81b35eb5eba893327354
|
|
| MD5 |
3ed27df4800fda134a68859eb2ff6854
|
|
| BLAKE2b-256 |
7f026cd752a21b6f02e6a7aa4c056e51c0a76cc82733ea4a7cabf553f10c1de4
|