Skip to main content

Calculator Library

python poetry GitHub AI license

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


Features

16 math calculator functions:

  • Two-operand operations: add, subtract, multiply, divide, power, nth_root, modulo, floor_divide
  • Single-operand operations: sqrt, absolute, floor, ceil, log10, ln, exp
  • Rounding: round_number (with configurable decimal places)

AI Disclaimer

This project includes code and documentation created with the assistance of AI tools. For details on usage, limits, and review practices, please see the AI Disclaimer.

Prerequisites

  • Python 3.14+
  • pip

Installation

  1. Install using pip
pip install calculator-lib-rubens
  1. Confirm the installed version matches the latest GitHub release at calculator-lib/releases
pip show calculator-lib-rubens

Uninstall

pip uninstall calculator-lib-rubens
pip cache purge

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:

from calculator_lib import Calculator

calc = Calculator()

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

Documentation

License

This project is licensed under the MIT License.


Author: Rubens Gomes

Metadata

Release files for calculator-lib-rubens 0.2.4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for calculator-lib-rubens 0.2.4
File Size Uploaded
calculator_lib_rubens-0.2.4.tar.gz 5.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for calculator-lib-rubens 0.2.4
File Interpreter ABI Platform
calculator_lib_rubens-0.2.4-py3-none-any.whl Python 3 none any Details

Total release size: 10.6 kB

Release files / calculator_lib_rubens-0.2.4.tar.gz

Download URL calculator_lib_rubens-0.2.4.tar.gz
Size 5.3 kB
Tags Source
SHA-256 checksum
How to use checksums
c1d73c2163241c173ae07c3fca0340b3adcacc11e240d463c83b6826b21e52c7
BLAKE2b-256 checksum
How to use checksums
8d8d53d6118cc0754a14d4d4fd3fb2c0f1be1adff29981a56ba271b90adc16c4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.4.3 CPython/3.14.7 Linux/6.17.0-1022-azure

Release files / calculator_lib_rubens-0.2.4-py3-none-any.whl

Download URL calculator_lib_rubens-0.2.4-py3-none-any.whl
Size 5.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
8037355a5cd472dfabd95688f2595b4f683cfeb16f37407d4f090a1ec4bcdcb3
BLAKE2b-256 checksum
How to use checksums
2bd84f677de6248798ecb253aac29331517121ba32b41c9ebf6bd47011bc7d25
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.4.3 CPython/3.14.7 Linux/6.17.0-1022-azure

Release history Release notifications | RSS feed

0.2.5

2 release files

This release

0.2.4 This release

2 release files

0.2.3

2 release files

0.2.2

2 release files

0.2.1

2 release files

0.2.0

2 release files

0.1.6

2 release files

0.1.5

2 release files

0.1.4

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page