Bignum â Arbitrary-Precision Decimal Numbers for Python
Bignum is a tiny wrapper around Pythonâs built-in decimal.Decimal type.
It gives you:
- Easy, consistent handling of big numbers (money, crypto, prices, etc.)
- Configurable precision (
DP) and rounding mode (RM)
Perfect when float is too imprecise and you want something safer but still easy to use.
Features
- â
Arbitrary-precision decimal arithmetic
- â
Global defaults for decimal places (
DP) and rounding mode (RM)
- â
Minimal, focused API
- â
Works with
str, int, float, Decimal, and Big values
Installation
If youâve published this as a package:
pip install bignum
Quick Start
from bignum import Big
a = Big("0.1")
b = Big("0.2")
c = a + b
print(c)
d = Big("1.23") * Big("4")
print(d)
Because Big uses Decimal under the hood, you donât get the usual floating-point surprises:
from bignum import Big
print(0.1 + 0.2)
print(Big("0.1") + Big("0.2"))
Configuration
Big exposes two important global settings:
from bignum import Big
Big.DP = 20
Big.RM = 1
Internally, these map to decimalâs rounding modes via _ROUND_MAP.
You can also use decimal.localcontext() for temporary precision overrides inside your own code, but for most use cases, setting Big.DP and Big.RM is enough.
Creating Big Numbers
from bignum import Big
from decimal import Decimal
Big("1.2345")
Big(12345)
Big(1.2345)
Big(Decimal("1.2345"))
Big(Big("1.2345"))
Under the hood, the constructor converts the value to a Decimal and stores it as self._d.
Arithmetic
The exact API here depends on how you implemented Big.
Below is a typical pattern using operator overloading.
Addition
x = Big("1.1")
y = Big("2.2")
print(x + y)
Subtraction
x = Big("5")
y = Big("2.5")
print(x - y)
Multiplication
x = Big("1.5")
y = Big("3")
print(x * y)
Division
Division respects Big.DP and Big.RM:
from bignum import Big
Big.DP = 10
Big.RM = 1
x = Big("1")
y = Big("3")
print(x / y)
License
MIT License
Copyright (c) 2025 kent-griffin