Skip to main content

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 โ‰ค 1
    • sec(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

  1. Clone the repository:

    git clone https://github.com/AryanSolanke/Calculator.git
    cd Calculator
    
  2. Run the calculator:

    python main.py
    

    Or:

    python -m calculator.main
    
  3. 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.py preserved 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:

  1. All tests pass before submitting PR
  2. New features include corresponding tests
  3. Code follows PEP 8 style guide
  4. Docstrings are provided for all functions
  5. 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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

aryan_advanced_calculator-1.2.1.tar.gz (39.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

aryan_advanced_calculator-1.2.1-py3-none-any.whl (47.2 kB view details)

Uploaded Python 3

File details

Details for the file aryan_advanced_calculator-1.2.1.tar.gz.

File metadata

File hashes

Hashes for aryan_advanced_calculator-1.2.1.tar.gz
Algorithm Hash digest
SHA256 28f279512baab418f5edefbe4af524d9627b25b75a3266e4e1e25d815daf1f74
MD5 0230a9c7b389a9a89512d3ba766aea80
BLAKE2b-256 bc51d8b8209ad810f540e65268d8c5944f3b7de5f416fe0a2bc006d300c9b09f

See more details on using hashes here.

File details

Details for the file aryan_advanced_calculator-1.2.1-py3-none-any.whl.

File metadata

File hashes

Hashes for aryan_advanced_calculator-1.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 e84648cca8a7ab4be24b81d53624a4c98c65ec6803fa81b35eb5eba893327354
MD5 3ed27df4800fda134a68859eb2ff6854
BLAKE2b-256 7f026cd752a21b6f02e6a7aa4c056e51c0a76cc82733ea4a7cabf553f10c1de4

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page