Skip to main content

A python calculator library.

Project description

Calculator-LIB

A Python calculator library providing stateless arithmetic, power/root, modulo, rounding, and logarithmic/exponential operations.

Python 3.14+ License: MIT

Installation

pip install calculator-lib-rubens

Quick Start

from calculator_lib import Calculator

calc = Calculator()

calc.add(2, 3)  # 5
calc.subtract(10, 4)  # 6
calc.multiply(3, 4)  # 12
calc.divide(10, 2)  # 5.0

API Reference

Core Arithmetic

Method Description
add(a, b) Returns the sum of a and b
subtract(a, b) Returns a minus b
multiply(a, b) Returns the product of a and b
divide(a, b) Returns a divided by b

Power & Roots

Method Description
power(a, b) Returns a raised to the power b
sqrt(a) Returns the square root of a
nth_root(a, n) Returns the n-th root of a

Modulo & Integer Math

Method Description
modulo(a, b) Returns the remainder of a / b
floor_divide(a, b) Returns the floor division of a / b

Absolute & Rounding

Method Description
absolute(a) Returns the absolute value of a
round_number(a, decimals=0) Rounds a to the given decimal places
floor(a) Returns the largest integer <= a
ceil(a) Returns the smallest integer >= a

Logarithmic & Exponential

Method Description
log10(a) Returns the base-10 logarithm of a
ln(a) Returns the natural logarithm of a
exp(a) Returns e raised to the power a

Usage Examples

import math
from calculator_lib import Calculator

calc = Calculator()

# Power & Roots
calc.power(2, 3)  # 8
calc.sqrt(16)  # 4.0
calc.nth_root(27, 3)  # 3.0

# Modulo & Rounding
calc.modulo(10, 3)  # 1
calc.floor_divide(7, 2)  # 3
calc.round_number(3.14159, 2)  # 3.14
calc.floor(3.7)  # 3.0
calc.ceil(3.2)  # 4.0

# Logarithmic & Exponential
calc.log10(100)  # 2.0
calc.ln(math.e)  # 1.0
calc.exp(1)  # 2.718281828459045

Error Handling

All methods validate their inputs and raise ValueError with descriptive messages for invalid operations:

calc.divide(10, 0)  # ValueError: Cannot divide by zero
calc.sqrt(-1)  # ValueError: Cannot take square root of a negative number
calc.log10(0)  # ValueError: Cannot take logarithm of a non-positive number
calc.nth_root(-4, 2)  # ValueError: Cannot take even root of a negative number
calc.modulo(10, 0)  # ValueError: Cannot modulo by zero

Requirements

  • Python 3.14+

License

Modified MIT

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

calculator_lib_rubens-0.1.4.tar.gz (4.5 kB view details)

Uploaded Source

Built Distribution

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

calculator_lib_rubens-0.1.4-py3-none-any.whl (5.3 kB view details)

Uploaded Python 3

File details

Details for the file calculator_lib_rubens-0.1.4.tar.gz.

File metadata

  • Download URL: calculator_lib_rubens-0.1.4.tar.gz
  • Upload date:
  • Size: 4.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.2.1 CPython/3.12.3 Linux/6.6.87.2-microsoft-standard-WSL2

File hashes

Hashes for calculator_lib_rubens-0.1.4.tar.gz
Algorithm Hash digest
SHA256 d5c5bdad2f6370177d57c6cb397b10ddb4f7f391ed7acd1fe2e3d0219587a2dc
MD5 d25a2aa305710f5fb663248884e6392b
BLAKE2b-256 0ddbf262473b5e7f8a969a76ccd70299e9475e5e6a170c52e08104679247c4b3

See more details on using hashes here.

File details

Details for the file calculator_lib_rubens-0.1.4-py3-none-any.whl.

File metadata

  • Download URL: calculator_lib_rubens-0.1.4-py3-none-any.whl
  • Upload date:
  • Size: 5.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.2.1 CPython/3.12.3 Linux/6.6.87.2-microsoft-standard-WSL2

File hashes

Hashes for calculator_lib_rubens-0.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 09e1063ad22b066312fdc8eca3511843788fb43d2616b9a40deb4781a58a8460
MD5 d790130e59d77e0b5e6233c192e4b23d
BLAKE2b-256 bfca18a07b6cd7210722c1c594969a18786db6c5c1b646b06ff3f5f91ee5000d

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