| 1 |
import numbers |
| 2 |
import sys |
| 3 |
from _decimal import ( |
| 4 |
HAVE_CONTEXTVAR as HAVE_CONTEXTVAR, |
| 5 |
HAVE_THREADS as HAVE_THREADS, |
| 6 |
MAX_EMAX as MAX_EMAX, |
| 7 |
MAX_PREC as MAX_PREC, |
| 8 |
MIN_EMIN as MIN_EMIN, |
| 9 |
MIN_ETINY as MIN_ETINY, |
| 10 |
ROUND_05UP as ROUND_05UP, |
| 11 |
ROUND_CEILING as ROUND_CEILING, |
| 12 |
ROUND_DOWN as ROUND_DOWN, |
| 13 |
ROUND_FLOOR as ROUND_FLOOR, |
| 14 |
ROUND_HALF_DOWN as ROUND_HALF_DOWN, |
| 15 |
ROUND_HALF_EVEN as ROUND_HALF_EVEN, |
| 16 |
ROUND_HALF_UP as ROUND_HALF_UP, |
| 17 |
ROUND_UP as ROUND_UP, |
| 18 |
BasicContext as BasicContext, |
| 19 |
DefaultContext as DefaultContext, |
| 20 |
ExtendedContext as ExtendedContext, |
| 21 |
__libmpdec_version__ as __libmpdec_version__, |
| 22 |
__version__ as __version__, |
| 23 |
getcontext as getcontext, |
| 24 |
localcontext as localcontext, |
| 25 |
setcontext as setcontext, |
| 26 |
) |
| 27 |
from collections.abc import Container, Sequence |
| 28 |
from types import TracebackType |
| 29 |
from typing import Any, ClassVar, Literal, NamedTuple, final, overload, type_check_only |
| 30 |
from typing_extensions import Self, TypeAlias, disjoint_base |
| 31 |
|
| 32 |
if sys.version_info >= (3, 14): |
| 33 |
from _decimal import IEEE_CONTEXT_MAX_BITS as IEEE_CONTEXT_MAX_BITS, IEEEContext as IEEEContext |
| 34 |
|
| 35 |
_Decimal: TypeAlias = Decimal | int |
| 36 |
_DecimalNew: TypeAlias = Decimal | float | str | tuple[int, Sequence[int], int] |
| 37 |
_ComparableNum: TypeAlias = Decimal | float | numbers.Rational |
| 38 |
_TrapType: TypeAlias = type[DecimalException] |
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
@final |
| 45 |
@type_check_only |
| 46 |
class _ContextManager: |
| 47 |
def __init__(self, new_context: Context) -> None: ... |
| 48 |
def __enter__(self) -> Context: ... |
| 49 |
def __exit__(self, t: type[BaseException] | None, v: BaseException | None, tb: TracebackType | None) -> None: ... |
| 50 |
|
| 51 |
class DecimalTuple(NamedTuple): |
| 52 |
sign: int |
| 53 |
digits: tuple[int, ...] |
| 54 |
exponent: int | Literal["n", "N", "F"] |
| 55 |
|
| 56 |
class DecimalException(ArithmeticError): ... |
| 57 |
class Clamped(DecimalException): ... |
| 58 |
class InvalidOperation(DecimalException): ... |
| 59 |
class ConversionSyntax(InvalidOperation): ... |
| 60 |
class DivisionByZero(DecimalException, ZeroDivisionError): ... |
| 61 |
class DivisionImpossible(InvalidOperation): ... |
| 62 |
class DivisionUndefined(InvalidOperation, ZeroDivisionError): ... |
| 63 |
class Inexact(DecimalException): ... |
| 64 |
class InvalidContext(InvalidOperation): ... |
| 65 |
class Rounded(DecimalException): ... |
| 66 |
class Subnormal(DecimalException): ... |
| 67 |
class Overflow(Inexact, Rounded): ... |
| 68 |
class Underflow(Inexact, Rounded, Subnormal): ... |
| 69 |
class FloatOperation(DecimalException, TypeError): ... |
| 70 |
|
| 71 |
@disjoint_base |
| 72 |
class Decimal: |
| 73 |
def __new__(cls, value: _DecimalNew = "0", context: Context | None = None) -> Self: ... |
| 74 |
if sys.version_info >= (3, 14): |
| 75 |
@classmethod |
| 76 |
def from_number(cls, number: Decimal | float, /) -> Self: ... |
| 77 |
|
| 78 |
@classmethod |
| 79 |
def from_float(cls, f: float, /) -> Self: ... |
| 80 |
def __bool__(self) -> bool: ... |
| 81 |
def compare(self, other: _Decimal, context: Context | None = None) -> Decimal: ... |
| 82 |
def __hash__(self) -> int: ... |
| 83 |
def as_tuple(self) -> DecimalTuple: ... |
| 84 |
def as_integer_ratio(self) -> tuple[int, int]: ... |
| 85 |
def to_eng_string(self, context: Context | None = None) -> str: ... |
| 86 |
def __abs__(self) -> Decimal: ... |
| 87 |
def __add__(self, value: _Decimal, /) -> Decimal: ... |
| 88 |
def __divmod__(self, value: _Decimal, /) -> tuple[Decimal, Decimal]: ... |
| 89 |
def __eq__(self, value: object, /) -> bool: ... |
| 90 |
def __floordiv__(self, value: _Decimal, /) -> Decimal: ... |
| 91 |
def __ge__(self, value: _ComparableNum, /) -> bool: ... |
| 92 |
def __gt__(self, value: _ComparableNum, /) -> bool: ... |
| 93 |
def __le__(self, value: _ComparableNum, /) -> bool: ... |
| 94 |
def __lt__(self, value: _ComparableNum, /) -> bool: ... |
| 95 |
def __mod__(self, value: _Decimal, /) -> Decimal: ... |
| 96 |
def __mul__(self, value: _Decimal, /) -> Decimal: ... |
| 97 |
def __neg__(self) -> Decimal: ... |
| 98 |
def __pos__(self) -> Decimal: ... |
| 99 |
def __pow__(self, value: _Decimal, mod: _Decimal | None = None, /) -> Decimal: ... |
| 100 |
def __radd__(self, value: _Decimal, /) -> Decimal: ... |
| 101 |
def __rdivmod__(self, value: _Decimal, /) -> tuple[Decimal, Decimal]: ... |
| 102 |
def __rfloordiv__(self, value: _Decimal, /) -> Decimal: ... |
| 103 |
def __rmod__(self, value: _Decimal, /) -> Decimal: ... |
| 104 |
def __rmul__(self, value: _Decimal, /) -> Decimal: ... |
| 105 |
def __rsub__(self, value: _Decimal, /) -> Decimal: ... |
| 106 |
def __rtruediv__(self, value: _Decimal, /) -> Decimal: ... |
| 107 |
def __sub__(self, value: _Decimal, /) -> Decimal: ... |
| 108 |
def __truediv__(self, value: _Decimal, /) -> Decimal: ... |
| 109 |
def remainder_near(self, other: _Decimal, context: Context | None = None) -> Decimal: ... |
| 110 |
def __float__(self) -> float: ... |
| 111 |
def __int__(self) -> int: ... |
| 112 |
def __trunc__(self) -> int: ... |
| 113 |
@property |
| 114 |
def real(self) -> Decimal: ... |
| 115 |
@property |
| 116 |
def imag(self) -> Decimal: ... |
| 117 |
def conjugate(self) -> Decimal: ... |
| 118 |
def __complex__(self) -> complex: ... |
| 119 |
@overload |
| 120 |
def __round__(self) -> int: ... |
| 121 |
@overload |
| 122 |
def __round__(self, ndigits: int, /) -> Decimal: ... |
| 123 |
def __floor__(self) -> int: ... |
| 124 |
def __ceil__(self) -> int: ... |
| 125 |
def fma(self, other: _Decimal, third: _Decimal, context: Context | None = None) -> Decimal: ... |
| 126 |
def __rpow__(self, value: _Decimal, mod: Context | None = None, /) -> Decimal: ... |
| 127 |
def normalize(self, context: Context | None = None) -> Decimal: ... |
| 128 |
def quantize(self, exp: _Decimal, rounding: str | None = None, context: Context | None = None) -> Decimal: ... |
| 129 |
def same_quantum(self, other: _Decimal, context: Context | None = None) -> bool: ... |
| 130 |
def to_integral_exact(self, rounding: str | None = None, context: Context | None = None) -> Decimal: ... |
| 131 |
def to_integral_value(self, rounding: str | None = None, context: Context | None = None) -> Decimal: ... |
| 132 |
def to_integral(self, rounding: str | None = None, context: Context | None = None) -> Decimal: ... |
| 133 |
def sqrt(self, context: Context | None = None) -> Decimal: ... |
| 134 |
def max(self, other: _Decimal, context: Context | None = None) -> Decimal: ... |
| 135 |
def min(self, other: _Decimal, context: Context | None = None) -> Decimal: ... |
| 136 |
def adjusted(self) -> int: ... |
| 137 |
def canonical(self) -> Decimal: ... |
| 138 |
def compare_signal(self, other: _Decimal, context: Context | None = None) -> Decimal: ... |
| 139 |
def compare_total(self, other: _Decimal, context: Context | None = None) -> Decimal: ... |
| 140 |
def compare_total_mag(self, other: _Decimal, context: Context | None = None) -> Decimal: ... |
| 141 |
def copy_abs(self) -> Decimal: ... |
| 142 |
def copy_negate(self) -> Decimal: ... |
| 143 |
def copy_sign(self, other: _Decimal, context: Context | None = None) -> Decimal: ... |
| 144 |
def exp(self, context: Context | None = None) -> Decimal: ... |
| 145 |
def is_canonical(self) -> bool: ... |
| 146 |
def is_finite(self) -> bool: ... |
| 147 |
def is_infinite(self) -> bool: ... |
| 148 |
def is_nan(self) -> bool: ... |
| 149 |
def is_normal(self, context: Context | None = None) -> bool: ... |
| 150 |
def is_qnan(self) -> bool: ... |
| 151 |
def is_signed(self) -> bool: ... |
| 152 |
def is_snan(self) -> bool: ... |
| 153 |
def is_subnormal(self, context: Context | None = None) -> bool: ... |
| 154 |
def is_zero(self) -> bool: ... |
| 155 |
def ln(self, context: Context | None = None) -> Decimal: ... |
| 156 |
def log10(self, context: Context | None = None) -> Decimal: ... |
| 157 |
def logb(self, context: Context | None = None) -> Decimal: ... |
| 158 |
def logical_and(self, other: _Decimal, context: Context | None = None) -> Decimal: ... |
| 159 |
def logical_invert(self, context: Context | None = None) -> Decimal: ... |
| 160 |
def logical_or(self, other: _Decimal, context: Context | None = None) -> Decimal: ... |
| 161 |
def logical_xor(self, other: _Decimal, context: Context | None = None) -> Decimal: ... |
| 162 |
def max_mag(self, other: _Decimal, context: Context | None = None) -> Decimal: ... |
| 163 |
def min_mag(self, other: _Decimal, context: Context | None = None) -> Decimal: ... |
| 164 |
def next_minus(self, context: Context | None = None) -> Decimal: ... |
| 165 |
def next_plus(self, context: Context | None = None) -> Decimal: ... |
| 166 |
def next_toward(self, other: _Decimal, context: Context | None = None) -> Decimal: ... |
| 167 |
def number_class(self, context: Context | None = None) -> str: ... |
| 168 |
def radix(self) -> Decimal: ... |
| 169 |
def rotate(self, other: _Decimal, context: Context | None = None) -> Decimal: ... |
| 170 |
def scaleb(self, other: _Decimal, context: Context | None = None) -> Decimal: ... |
| 171 |
def shift(self, other: _Decimal, context: Context | None = None) -> Decimal: ... |
| 172 |
def __reduce__(self) -> tuple[type[Self], tuple[str]]: ... |
| 173 |
def __copy__(self) -> Self: ... |
| 174 |
def __deepcopy__(self, memo: Any, /) -> Self: ... |
| 175 |
def __format__(self, specifier: str, context: Context | None = None, /) -> str: ... |
| 176 |
|
| 177 |
@disjoint_base |
| 178 |
class Context: |
| 179 |
|
| 180 |
|
| 181 |
|
| 182 |
|
| 183 |
|
| 184 |
prec: int |
| 185 |
rounding: str |
| 186 |
Emin: int |
| 187 |
Emax: int |
| 188 |
capitals: int |
| 189 |
clamp: int |
| 190 |
traps: dict[_TrapType, bool] |
| 191 |
flags: dict[_TrapType, bool] |
| 192 |
def __init__( |
| 193 |
self, |
| 194 |
prec: int | None = None, |
| 195 |
rounding: str | None = None, |
| 196 |
Emin: int | None = None, |
| 197 |
Emax: int | None = None, |
| 198 |
capitals: int | None = None, |
| 199 |
clamp: int | None = None, |
| 200 |
flags: dict[_TrapType, bool] | Container[_TrapType] | None = None, |
| 201 |
traps: dict[_TrapType, bool] | Container[_TrapType] | None = None, |
| 202 |
) -> None: ... |
| 203 |
def __reduce__(self) -> tuple[type[Self], tuple[Any, ...]]: ... |
| 204 |
def clear_flags(self) -> None: ... |
| 205 |
def clear_traps(self) -> None: ... |
| 206 |
def copy(self) -> Context: ... |
| 207 |
def __copy__(self) -> Context: ... |
| 208 |
|
| 209 |
__hash__: ClassVar[None] |
| 210 |
def Etiny(self) -> int: ... |
| 211 |
def Etop(self) -> int: ... |
| 212 |
def create_decimal(self, num: _DecimalNew = "0", /) -> Decimal: ... |
| 213 |
def create_decimal_from_float(self, f: float, /) -> Decimal: ... |
| 214 |
def abs(self, x: _Decimal, /) -> Decimal: ... |
| 215 |
def add(self, x: _Decimal, y: _Decimal, /) -> Decimal: ... |
| 216 |
def canonical(self, x: Decimal, /) -> Decimal: ... |
| 217 |
def compare(self, x: _Decimal, y: _Decimal, /) -> Decimal: ... |
| 218 |
def compare_signal(self, x: _Decimal, y: _Decimal, /) -> Decimal: ... |
| 219 |
def compare_total(self, x: _Decimal, y: _Decimal, /) -> Decimal: ... |
| 220 |
def compare_total_mag(self, x: _Decimal, y: _Decimal, /) -> Decimal: ... |
| 221 |
def copy_abs(self, x: _Decimal, /) -> Decimal: ... |
| 222 |
def copy_decimal(self, x: _Decimal, /) -> Decimal: ... |
| 223 |
def copy_negate(self, x: _Decimal, /) -> Decimal: ... |
| 224 |
def copy_sign(self, x: _Decimal, y: _Decimal, /) -> Decimal: ... |
| 225 |
def divide(self, x: _Decimal, y: _Decimal, /) -> Decimal: ... |
| 226 |
def divide_int(self, x: _Decimal, y: _Decimal, /) -> Decimal: ... |
| 227 |
def divmod(self, x: _Decimal, y: _Decimal, /) -> tuple[Decimal, Decimal]: ... |
| 228 |
def exp(self, x: _Decimal, /) -> Decimal: ... |
| 229 |
def fma(self, x: _Decimal, y: _Decimal, z: _Decimal, /) -> Decimal: ... |
| 230 |
def is_canonical(self, x: _Decimal, /) -> bool: ... |
| 231 |
def is_finite(self, x: _Decimal, /) -> bool: ... |
| 232 |
def is_infinite(self, x: _Decimal, /) -> bool: ... |
| 233 |
def is_nan(self, x: _Decimal, /) -> bool: ... |
| 234 |
def is_normal(self, x: _Decimal, /) -> bool: ... |
| 235 |
def is_qnan(self, x: _Decimal, /) -> bool: ... |
| 236 |
def is_signed(self, x: _Decimal, /) -> bool: ... |
| 237 |
def is_snan(self, x: _Decimal, /) -> bool: ... |
| 238 |
def is_subnormal(self, x: _Decimal, /) -> bool: ... |
| 239 |
def is_zero(self, x: _Decimal, /) -> bool: ... |
| 240 |
def ln(self, x: _Decimal, /) -> Decimal: ... |
| 241 |
def log10(self, x: _Decimal, /) -> Decimal: ... |
| 242 |
def logb(self, x: _Decimal, /) -> Decimal: ... |
| 243 |
def logical_and(self, x: _Decimal, y: _Decimal, /) -> Decimal: ... |
| 244 |
def logical_invert(self, x: _Decimal, /) -> Decimal: ... |
| 245 |
def logical_or(self, x: _Decimal, y: _Decimal, /) -> Decimal: ... |
| 246 |
def logical_xor(self, x: _Decimal, y: _Decimal, /) -> Decimal: ... |
| 247 |
def max(self, x: _Decimal, y: _Decimal, /) -> Decimal: ... |
| 248 |
def max_mag(self, x: _Decimal, y: _Decimal, /) -> Decimal: ... |
| 249 |
def min(self, x: _Decimal, y: _Decimal, /) -> Decimal: ... |
| 250 |
def min_mag(self, x: _Decimal, y: _Decimal, /) -> Decimal: ... |
| 251 |
def minus(self, x: _Decimal, /) -> Decimal: ... |
| 252 |
def multiply(self, x: _Decimal, y: _Decimal, /) -> Decimal: ... |
| 253 |
def next_minus(self, x: _Decimal, /) -> Decimal: ... |
| 254 |
def next_plus(self, x: _Decimal, /) -> Decimal: ... |
| 255 |
def next_toward(self, x: _Decimal, y: _Decimal, /) -> Decimal: ... |
| 256 |
def normalize(self, x: _Decimal, /) -> Decimal: ... |
| 257 |
def number_class(self, x: _Decimal, /) -> str: ... |
| 258 |
def plus(self, x: _Decimal, /) -> Decimal: ... |
| 259 |
def power(self, a: _Decimal, b: _Decimal, modulo: _Decimal | None = None) -> Decimal: ... |
| 260 |
def quantize(self, x: _Decimal, y: _Decimal, /) -> Decimal: ... |
| 261 |
def radix(self) -> Decimal: ... |
| 262 |
def remainder(self, x: _Decimal, y: _Decimal, /) -> Decimal: ... |
| 263 |
def remainder_near(self, x: _Decimal, y: _Decimal, /) -> Decimal: ... |
| 264 |
def rotate(self, x: _Decimal, y: _Decimal, /) -> Decimal: ... |
| 265 |
def same_quantum(self, x: _Decimal, y: _Decimal, /) -> bool: ... |
| 266 |
def scaleb(self, x: _Decimal, y: _Decimal, /) -> Decimal: ... |
| 267 |
def shift(self, x: _Decimal, y: _Decimal, /) -> Decimal: ... |
| 268 |
def sqrt(self, x: _Decimal, /) -> Decimal: ... |
| 269 |
def subtract(self, x: _Decimal, y: _Decimal, /) -> Decimal: ... |
| 270 |
def to_eng_string(self, x: _Decimal, /) -> str: ... |
| 271 |
def to_sci_string(self, x: _Decimal, /) -> str: ... |
| 272 |
def to_integral_exact(self, x: _Decimal, /) -> Decimal: ... |
| 273 |
def to_integral_value(self, x: _Decimal, /) -> Decimal: ... |
| 274 |
def to_integral(self, x: _Decimal, /) -> Decimal: ... |