Skip to main content

Performing calculations in Sexagesimal Coordinate System.

Project description

Sexagesimal Calculator

PyPI version Python versions Coverage Status Pepy Total Downloads Conventional Commits License: MIT GitHub stars GitHub issues uv Ruff

A robust, modern Python library for high-precision sexagesimal (base-60) arithmetic, born from a project for the History of Mathematics in India (HoMI) initiative at Indian Institute of Technology, Gandhinagar.

This library provides a Sexagesimal class that represents numbers as immutable objects, allowing for intuitive and accurate calculations. It is ideal for applications in historical mathematics, astronomy, and any domain requiring base-60 computation.

Features

  • Immutable Objects: Sexagesimal numbers are immutable, ensuring predictable and bug-free calculations.
  • Intuitive API: Use standard Python operators (+, -, *, /, **, round()) for all arithmetic.
  • High Precision: Backed by Python's Decimal and sympy.Rational for conversions, guaranteeing precision.
  • Flexible Initialization: Create Sexagesimal numbers from integers, floats, decimals, or strings.
  • Educational Tools: Generate beautiful, step-by-step explanations of calculations, perfect for teaching or validation.
  • Fully Typed and Tested: High test coverage with a comprehensive pytest and hypothesis suite.

Installation

This package is hosted on PyPI.

pip install sexagesimal-calculator

# OR

uv add sexagesimal-calculator

Basic Usage

The core of the library is the Sexagesimal class.

from sexagesimal_calculator import Sexagesimal

# Initialization is flexible
a = Sexagesimal("10;15,30") # From a sexagesimal string
b = Sexagesimal(1.75)       # From a float
c = Sexagesimal("-5")       # From an integer string

print(f"A = {a}") # A = 10;15,30
print(f"B = {b}") # B = 01;45
print(f"C = {c}") # C = -05;00

# Arithmetic uses standard Python operators
sum_val = a + b
print(f"A + B = {sum_val}") # A + B = 12;00,30

# Convert to a high-precision Decimal
dec_val = sum_val.to_decimal()
print(f"Sum as Decimal: {dec_val}") # Sum as Decimal: 12.008333...

# Rounding
rounded = Sexagesimal("21;19,53,47").round(precision=2)
print(f"Rounded value: {rounded}") # Rounded value: 21;19,54

Explanations Feature

A standout feature is the ability to generate detailed, step-by-step explanations for calculations.

from sexagesimal_calculator import explain_multiplication

a = Sexagesimal("01;15")
b = Sexagesimal("02;30")

# Generate the explanation object
explanation = explain_multiplication(a, b)

# Print the beautiful, colored explanation to your terminal
explanation.print()

This produces a detailed, formatted breakdown of the entire long multiplication process, perfect for educational purposes. Similar functions (explain_addition, explain_subtraction, explain_division) are also available.

Development

To set up for development, clone the repository and use uv to sync dependencies.

git clone https://github.com/HrushikeshPawar/Sexagesimal-Calculator.git
cd Sexagesimal-Calculator
uv sync --all-packages

To run the test suite with coverage:

uv run pytest --cov=src/sexagesimal_calculator

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

sexagesimal_calculator-2.0.0.tar.gz (19.4 kB view details)

Uploaded Source

Built Distribution

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

sexagesimal_calculator-2.0.0-py3-none-any.whl (23.8 kB view details)

Uploaded Python 3

File details

Details for the file sexagesimal_calculator-2.0.0.tar.gz.

File metadata

File hashes

Hashes for sexagesimal_calculator-2.0.0.tar.gz
Algorithm Hash digest
SHA256 a70ac6ab3a5f42c11f45ec00a866a9a41e4ecad453175dbb1273b6bdd84e29b0
MD5 55bbcfbf9f676ab29450e1e4d74cb404
BLAKE2b-256 d0c740cbc9c982803fd372ce8bc89d49e3cba731ed063041d2be75b9961f58e1

See more details on using hashes here.

File details

Details for the file sexagesimal_calculator-2.0.0-py3-none-any.whl.

File metadata

File hashes

Hashes for sexagesimal_calculator-2.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 cac87f24e84f81374d2969e7d14a0597c7bd275ea140314015fc426571bf02c9
MD5 3d6a81fd265f79430458929eb7638576
BLAKE2b-256 fa632cab309df5ba2f46f4b3e929b16517beabaf8cdb74282d61b36b25987ae4

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