2 from types import TracebackType
3 from typing import Any, Container, NamedTuple, Sequence, Tuple, Type, TypeVar, Union, overload
5 _Decimal = Union[Decimal, int]
6 _DecimalNew = Union[Decimal, float, str, Tuple[int, Sequence[int], int]]
7 _ComparableNum = Union[Decimal, float, numbers.Rational]
8 _DecimalT = TypeVar("_DecimalT", bound=Decimal)
10 class DecimalTuple(NamedTuple):
12 digits: Tuple[int, ...]
30 class DecimalException(ArithmeticError): ...
31 class Clamped(DecimalException): ...
32 class InvalidOperation(DecimalException): ...
33 class ConversionSyntax(InvalidOperation): ...
34 class DivisionByZero(DecimalException, ZeroDivisionError): ...
35 class DivisionImpossible(InvalidOperation): ...
36 class DivisionUndefined(InvalidOperation, ZeroDivisionError): ...
37 class Inexact(DecimalException): ...
38 class InvalidContext(InvalidOperation): ...
39 class Rounded(DecimalException): ...
40 class Subnormal(DecimalException): ...
41 class Overflow(Inexact, Rounded): ...
42 class Underflow(Inexact, Rounded, Subnormal): ...
43 class FloatOperation(DecimalException, TypeError): ...
45 def setcontext(__context: Context) -> None: ...
46 def getcontext() -> Context: ...
47 def localcontext(ctx: Context | None = ...) -> _ContextManager: ...
49 class Decimal(object):
50 def __new__(cls: Type[_DecimalT], value: _DecimalNew = ..., context: Context | None = ...) -> _DecimalT: ...
52 def from_float(cls, __f: float) -> Decimal: ...
53 def __bool__(self) -> bool: ...
54 def compare(self, other: _Decimal, context: Context | None = ...) -> Decimal: ...
55 def __hash__(self) -> int: ...
56 def as_tuple(self) -> DecimalTuple: ...
57 def as_integer_ratio(self) -> tuple[int, int]: ...
58 def to_eng_string(self, context: Context | None = ...) -> str: ...
59 def __abs__(self) -> Decimal: ...
60 def __add__(self, __other: _Decimal) -> Decimal: ...
61 def __divmod__(self, __other: _Decimal) -> tuple[Decimal, Decimal]: ...
62 def __eq__(self, __other: object) -> bool: ...
63 def __floordiv__(self, __other: _Decimal) -> Decimal: ...
64 def __ge__(self, __other: _ComparableNum) -> bool: ...
65 def __gt__(self, __other: _ComparableNum) -> bool: ...
66 def __le__(self, __other: _ComparableNum) -> bool: ...
67 def __lt__(self, __other: _ComparableNum) -> bool: ...
68 def __mod__(self, __other: _Decimal) -> Decimal: ...
69 def __mul__(self, __other: _Decimal) -> Decimal: ...
70 def __neg__(self) -> Decimal: ...
71 def __pos__(self) -> Decimal: ...
72 def __pow__(self, __other: _Decimal, __modulo: _Decimal | None = ...) -> Decimal: ...
73 def __radd__(self, __other: _Decimal) -> Decimal: ...
74 def __rdivmod__(self, __other: _Decimal) -> tuple[Decimal, Decimal]: ...
75 def __rfloordiv__(self, __other: _Decimal) -> Decimal: ...
76 def __rmod__(self, __other: _Decimal) -> Decimal: ...
77 def __rmul__(self, __other: _Decimal) -> Decimal: ...
78 def __rsub__(self, __other: _Decimal) -> Decimal: ...
79 def __rtruediv__(self, __other: _Decimal) -> Decimal: ...
80 def __str__(self) -> str: ...
81 def __sub__(self, __other: _Decimal) -> Decimal: ...
82 def __truediv__(self, __other: _Decimal) -> Decimal: ...
83 def remainder_near(self, other: _Decimal, context: Context | None = ...) -> Decimal: ...
84 def __float__(self) -> float: ...
85 def __int__(self) -> int: ...
86 def __trunc__(self) -> int: ...
88 def real(self) -> Decimal: ...
90 def imag(self) -> Decimal: ...
91 def conjugate(self) -> Decimal: ...
92 def __complex__(self) -> complex: ...
94 def __round__(self) -> int: ...
96 def __round__(self, __ndigits: int) -> Decimal: ...
97 def __floor__(self) -> int: ...
98 def __ceil__(self) -> int: ...
99 def fma(self, other: _Decimal, third: _Decimal, context: Context | None = ...) -> Decimal: ...
100 def __rpow__(self, __other: _Decimal, __context: Context | None = ...) -> Decimal: ...
101 def normalize(self, context: Context | None = ...) -> Decimal: ...
102 def quantize(self, exp: _Decimal, rounding: str | None = ..., context: Context | None = ...) -> Decimal: ...
103 def same_quantum(self, other: _Decimal, context: Context | None = ...) -> bool: ...
104 def to_integral_exact(self, rounding: str | None = ..., context: Context | None = ...) -> Decimal: ...
105 def to_integral_value(self, rounding: str | None = ..., context: Context | None = ...) -> Decimal: ...
106 def to_integral(self, rounding: str | None = ..., context: Context | None = ...) -> Decimal: ...
107 def sqrt(self, context: Context | None = ...) -> Decimal: ...
108 def max(self, other: _Decimal, context: Context | None = ...) -> Decimal: ...
109 def min(self, other: _Decimal, context: Context | None = ...) -> Decimal: ...
110 def adjusted(self) -> int: ...
111 def canonical(self) -> Decimal: ...
112 def compare_signal(self, other: _Decimal, context: Context | None = ...) -> Decimal: ...
113 def compare_total(self, other: _Decimal, context: Context | None = ...) -> Decimal: ...
114 def compare_total_mag(self, other: _Decimal, context: Context | None = ...) -> Decimal: ...
115 def copy_abs(self) -> Decimal: ...
116 def copy_negate(self) -> Decimal: ...
117 def copy_sign(self, other: _Decimal, context: Context | None = ...) -> Decimal: ...
118 def exp(self, context: Context | None = ...) -> Decimal: ...
119 def is_canonical(self) -> bool: ...
120 def is_finite(self) -> bool: ...
121 def is_infinite(self) -> bool: ...
122 def is_nan(self) -> bool: ...
123 def is_normal(self, context: Context | None = ...) -> bool: ...
124 def is_qnan(self) -> bool: ...
125 def is_signed(self) -> bool: ...
126 def is_snan(self) -> bool: ...
127 def is_subnormal(self, context: Context | None = ...) -> bool: ...
128 def is_zero(self) -> bool: ...
129 def ln(self, context: Context | None = ...) -> Decimal: ...
130 def log10(self, context: Context | None = ...) -> Decimal: ...
131 def logb(self, context: Context | None = ...) -> Decimal: ...
132 def logical_and(self, other: _Decimal, context: Context | None = ...) -> Decimal: ...
133 def logical_invert(self, context: Context | None = ...) -> Decimal: ...
134 def logical_or(self, other: _Decimal, context: Context | None = ...) -> Decimal: ...
135 def logical_xor(self, other: _Decimal, context: Context | None = ...) -> Decimal: ...
136 def max_mag(self, other: _Decimal, context: Context | None = ...) -> Decimal: ...
137 def min_mag(self, other: _Decimal, context: Context | None = ...) -> Decimal: ...
138 def next_minus(self, context: Context | None = ...) -> Decimal: ...
139 def next_plus(self, context: Context | None = ...) -> Decimal: ...
140 def next_toward(self, other: _Decimal, context: Context | None = ...) -> Decimal: ...
141 def number_class(self, context: Context | None = ...) -> str: ...
142 def radix(self) -> Decimal: ...
143 def rotate(self, other: _Decimal, context: Context | None = ...) -> Decimal: ...
144 def scaleb(self, other: _Decimal, context: Context | None = ...) -> Decimal: ...
145 def shift(self, other: _Decimal, context: Context | None = ...) -> Decimal: ...
146 def __reduce__(self) -> tuple[Type[Decimal], tuple[str]]: ...
147 def __copy__(self) -> Decimal: ...
148 def __deepcopy__(self, __memo: Any) -> Decimal: ...
149 def __format__(self, __specifier: str, __context: Context | None = ...) -> str: ...
151 class _ContextManager(object):
153 saved_context: Context
154 def __init__(self, new_context: Context) -> None: ...
155 def __enter__(self) -> Context: ...
156 def __exit__(self, t: Type[BaseException] | None, v: BaseException | None, tb: TracebackType | None) -> None: ...
158 _TrapType = Type[DecimalException]
160 class Context(object):
167 traps: dict[_TrapType, bool]
168 flags: dict[_TrapType, bool]
171 prec: int | None = ...,
172 rounding: str | None = ...,
173 Emin: int | None = ...,
174 Emax: int | None = ...,
175 capitals: int | None = ...,
176 clamp: int | None = ...,
177 flags: None | dict[_TrapType, bool] | Container[_TrapType] = ...,
178 traps: None | dict[_TrapType, bool] | Container[_TrapType] = ...,
179 _ignored_flags: list[_TrapType] | None = ...,
181 # __setattr__() only allows to set a specific set of attributes,
182 # already defined above.
183 def __delattr__(self, __name: str) -> None: ...
184 def __reduce__(self) -> tuple[Type[Context], Tuple[Any, ...]]: ...
185 def clear_flags(self) -> None: ...
186 def clear_traps(self) -> None: ...
187 def copy(self) -> Context: ...
188 def __copy__(self) -> Context: ...
190 def Etiny(self) -> int: ...
191 def Etop(self) -> int: ...
192 def create_decimal(self, __num: _DecimalNew = ...) -> Decimal: ...
193 def create_decimal_from_float(self, __f: float) -> Decimal: ...
194 def abs(self, __x: _Decimal) -> Decimal: ...
195 def add(self, __x: _Decimal, __y: _Decimal) -> Decimal: ...
196 def canonical(self, __x: Decimal) -> Decimal: ...
197 def compare(self, __x: _Decimal, __y: _Decimal) -> Decimal: ...
198 def compare_signal(self, __x: _Decimal, __y: _Decimal) -> Decimal: ...
199 def compare_total(self, __x: _Decimal, __y: _Decimal) -> Decimal: ...
200 def compare_total_mag(self, __x: _Decimal, __y: _Decimal) -> Decimal: ...
201 def copy_abs(self, __x: _Decimal) -> Decimal: ...
202 def copy_decimal(self, __x: _Decimal) -> Decimal: ...
203 def copy_negate(self, __x: _Decimal) -> Decimal: ...
204 def copy_sign(self, __x: _Decimal, __y: _Decimal) -> Decimal: ...
205 def divide(self, __x: _Decimal, __y: _Decimal) -> Decimal: ...
206 def divide_int(self, __x: _Decimal, __y: _Decimal) -> Decimal: ...
207 def divmod(self, __x: _Decimal, __y: _Decimal) -> tuple[Decimal, Decimal]: ...
208 def exp(self, __x: _Decimal) -> Decimal: ...
209 def fma(self, __x: _Decimal, __y: _Decimal, __z: _Decimal) -> Decimal: ...
210 def is_canonical(self, __x: _Decimal) -> bool: ...
211 def is_finite(self, __x: _Decimal) -> bool: ...
212 def is_infinite(self, __x: _Decimal) -> bool: ...
213 def is_nan(self, __x: _Decimal) -> bool: ...
214 def is_normal(self, __x: _Decimal) -> bool: ...
215 def is_qnan(self, __x: _Decimal) -> bool: ...
216 def is_signed(self, __x: _Decimal) -> bool: ...
217 def is_snan(self, __x: _Decimal) -> bool: ...
218 def is_subnormal(self, __x: _Decimal) -> bool: ...
219 def is_zero(self, __x: _Decimal) -> bool: ...
220 def ln(self, __x: _Decimal) -> Decimal: ...
221 def log10(self, __x: _Decimal) -> Decimal: ...
222 def logb(self, __x: _Decimal) -> Decimal: ...
223 def logical_and(self, __x: _Decimal, __y: _Decimal) -> Decimal: ...
224 def logical_invert(self, __x: _Decimal) -> Decimal: ...
225 def logical_or(self, __x: _Decimal, __y: _Decimal) -> Decimal: ...
226 def logical_xor(self, __x: _Decimal, __y: _Decimal) -> Decimal: ...
227 def max(self, __x: _Decimal, __y: _Decimal) -> Decimal: ...
228 def max_mag(self, __x: _Decimal, __y: _Decimal) -> Decimal: ...
229 def min(self, __x: _Decimal, __y: _Decimal) -> Decimal: ...
230 def min_mag(self, __x: _Decimal, __y: _Decimal) -> Decimal: ...
231 def minus(self, __x: _Decimal) -> Decimal: ...
232 def multiply(self, __x: _Decimal, __y: _Decimal) -> Decimal: ...
233 def next_minus(self, __x: _Decimal) -> Decimal: ...
234 def next_plus(self, __x: _Decimal) -> Decimal: ...
235 def next_toward(self, __x: _Decimal, __y: _Decimal) -> Decimal: ...
236 def normalize(self, __x: _Decimal) -> Decimal: ...
237 def number_class(self, __x: _Decimal) -> str: ...
238 def plus(self, __x: _Decimal) -> Decimal: ...
239 def power(self, a: _Decimal, b: _Decimal, modulo: _Decimal | None = ...) -> Decimal: ...
240 def quantize(self, __x: _Decimal, __y: _Decimal) -> Decimal: ...
241 def radix(self) -> Decimal: ...
242 def remainder(self, __x: _Decimal, __y: _Decimal) -> Decimal: ...
243 def remainder_near(self, __x: _Decimal, __y: _Decimal) -> Decimal: ...
244 def rotate(self, __x: _Decimal, __y: _Decimal) -> Decimal: ...
245 def same_quantum(self, __x: _Decimal, __y: _Decimal) -> bool: ...
246 def scaleb(self, __x: _Decimal, __y: _Decimal) -> Decimal: ...
247 def shift(self, __x: _Decimal, __y: _Decimal) -> Decimal: ...
248 def sqrt(self, __x: _Decimal) -> Decimal: ...
249 def subtract(self, __x: _Decimal, __y: _Decimal) -> Decimal: ...
250 def to_eng_string(self, __x: _Decimal) -> str: ...
251 def to_sci_string(self, __x: _Decimal) -> str: ...
252 def to_integral_exact(self, __x: _Decimal) -> Decimal: ...
253 def to_integral_value(self, __x: _Decimal) -> Decimal: ...
254 def to_integral(self, __x: _Decimal) -> Decimal: ...
256 DefaultContext: Context
257 BasicContext: Context
258 ExtendedContext: Context