basedpyright 1.40.1 → 1.40.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/pyright-langserver.js +1 -1
- package/dist/pyright.js +1 -1
- package/dist/typeshed-fallback/stdlib/_blake2.pyi +1 -1
- package/dist/typeshed-fallback/stdlib/_curses.pyi +81 -54
- package/dist/typeshed-fallback/stdlib/_curses_panel.pyi +8 -1
- package/dist/typeshed-fallback/stdlib/_decimal.pyi +9 -6
- package/dist/typeshed-fallback/stdlib/_interpqueues.pyi +24 -36
- package/dist/typeshed-fallback/stdlib/_interpreters.pyi +26 -71
- package/dist/typeshed-fallback/stdlib/_json.pyi +15 -11
- package/dist/typeshed-fallback/stdlib/_remote_debugging.pyi +355 -72
- package/dist/typeshed-fallback/stdlib/_socket.pyi +21 -21
- package/dist/typeshed-fallback/stdlib/_sqlite3.pyi +0 -15
- package/dist/typeshed-fallback/stdlib/_struct.pyi +39 -42
- package/dist/typeshed-fallback/stdlib/_thread.pyi +18 -14
- package/dist/typeshed-fallback/stdlib/array.pyi +8 -4
- package/dist/typeshed-fallback/stdlib/ast.pyi +9 -3
- package/dist/typeshed-fallback/stdlib/binascii.pyi +113 -10
- package/dist/typeshed-fallback/stdlib/builtins.pyi +260 -43
- package/dist/typeshed-fallback/stdlib/collections/__init__.pyi +12 -4
- package/dist/typeshed-fallback/stdlib/dataclasses.pyi +3 -1
- package/dist/typeshed-fallback/stdlib/datetime.pyi +93 -25
- package/dist/typeshed-fallback/stdlib/decimal.pyi +272 -208
- package/dist/typeshed-fallback/stdlib/faulthandler.pyi +29 -4
- package/dist/typeshed-fallback/stdlib/fcntl.pyi +6 -12
- package/dist/typeshed-fallback/stdlib/importlib/metadata/__init__.pyi +2 -0
- package/dist/typeshed-fallback/stdlib/json/encoder.pyi +2 -10
- package/dist/typeshed-fallback/stdlib/marshal.pyi +33 -2
- package/dist/typeshed-fallback/stdlib/math/__init__.pyi +15 -7
- package/dist/typeshed-fallback/stdlib/math/integer.pyi +43 -8
- package/dist/typeshed-fallback/stdlib/mmap.pyi +1 -1
- package/dist/typeshed-fallback/stdlib/os/__init__.pyi +60 -4
- package/dist/typeshed-fallback/stdlib/posixpath.pyi +14 -2
- package/dist/typeshed-fallback/stdlib/profiling/__init__.pyi +3 -3
- package/dist/typeshed-fallback/stdlib/profiling/sampling/__init__.pyi +17 -17
- package/dist/typeshed-fallback/stdlib/profiling/sampling/collector.pyi +25 -25
- package/dist/typeshed-fallback/stdlib/profiling/sampling/gecko_collector.pyi +111 -111
- package/dist/typeshed-fallback/stdlib/profiling/sampling/heatmap_collector.pyi +24 -24
- package/dist/typeshed-fallback/stdlib/profiling/sampling/jsonl_collector.pyi +15 -15
- package/dist/typeshed-fallback/stdlib/profiling/sampling/pstats_collector.pyi +17 -17
- package/dist/typeshed-fallback/stdlib/profiling/sampling/stack_collector.pyi +39 -39
- package/dist/typeshed-fallback/stdlib/profiling/sampling/string_table.pyi +5 -5
- package/dist/typeshed-fallback/stdlib/profiling/tracing.pyi +9 -9
- package/dist/typeshed-fallback/stdlib/pyexpat/__init__.pyi +24 -18
- package/dist/typeshed-fallback/stdlib/re.pyi +18 -3
- package/dist/typeshed-fallback/stdlib/select.pyi +2 -2
- package/dist/typeshed-fallback/stdlib/signal.pyi +1 -1
- package/dist/typeshed-fallback/stdlib/sqlite3/__init__.pyi +28 -5
- package/dist/typeshed-fallback/stdlib/sys/__init__.pyi +42 -4
- package/dist/typeshed-fallback/stdlib/types.pyi +44 -14
- package/dist/typeshed-fallback/stdlib/unicodedata.pyi +27 -9
- package/dist/typeshed-fallback/stdlib/urllib/parse.pyi +132 -6
- package/dist/typeshed-fallback/stdlib/winreg.pyi +5 -0
- package/dist/typeshed-fallback/stdlib/xml/utils.pyi +2 -2
- package/dist/typeshed-fallback/stdlib/zlib.pyi +34 -2
- package/package.json +1 -1
|
@@ -110,12 +110,14 @@ class Decimal:
|
|
|
110
110
|
...
|
|
111
111
|
def compare(self, other: _Decimal, context: Context | None = None) -> Decimal:
|
|
112
112
|
"""
|
|
113
|
-
Compare self to other.
|
|
113
|
+
Compare self to other.
|
|
114
114
|
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
115
|
+
Return a decimal value:
|
|
116
|
+
|
|
117
|
+
a or b is a NaN ==> Decimal('NaN')
|
|
118
|
+
a < b ==> Decimal('-1')
|
|
119
|
+
a == b ==> Decimal('0')
|
|
120
|
+
a > b ==> Decimal('1')
|
|
119
121
|
"""
|
|
120
122
|
...
|
|
121
123
|
def __hash__(self) -> int:
|
|
@@ -126,21 +128,23 @@ class Decimal:
|
|
|
126
128
|
...
|
|
127
129
|
def as_integer_ratio(self) -> tuple[int, int]:
|
|
128
130
|
"""
|
|
129
|
-
|
|
131
|
+
Return a pair of integers whose ratio is exactly equal to the original.
|
|
130
132
|
|
|
131
|
-
|
|
132
|
-
Decimal and with a positive denominator. The ratio is in lowest terms.
|
|
133
|
+
The ratio is in lowest terms and with a positive denominator.
|
|
133
134
|
Raise OverflowError on infinities and a ValueError on NaNs.
|
|
134
135
|
"""
|
|
135
136
|
...
|
|
136
137
|
def to_eng_string(self, context: Context | None = None) -> str:
|
|
137
138
|
"""
|
|
138
|
-
Convert to an engineering-type string.
|
|
139
|
-
|
|
140
|
-
|
|
139
|
+
Convert to an engineering-type string.
|
|
140
|
+
|
|
141
|
+
Engineering notation has an exponent which is a multiple of 3, so
|
|
142
|
+
there are up to 3 digits left of the decimal place. For example,
|
|
143
|
+
Decimal('123E+1') is converted to Decimal('1.23E+3').
|
|
141
144
|
|
|
142
|
-
The value of context.capitals determines whether the exponent sign
|
|
143
|
-
or upper case.
|
|
145
|
+
The value of context.capitals determines whether the exponent sign
|
|
146
|
+
is lower or upper case. Otherwise, the context does not affect the
|
|
147
|
+
operation.
|
|
144
148
|
"""
|
|
145
149
|
...
|
|
146
150
|
def __abs__(self) -> Decimal:
|
|
@@ -214,11 +218,13 @@ class Decimal:
|
|
|
214
218
|
...
|
|
215
219
|
def remainder_near(self, other: _Decimal, context: Context | None = None) -> Decimal:
|
|
216
220
|
"""
|
|
217
|
-
Return the remainder from dividing self by other.
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
221
|
+
Return the remainder from dividing self by other.
|
|
222
|
+
|
|
223
|
+
This differs from self % other in that the sign of the remainder is
|
|
224
|
+
chosen so as to minimize its absolute value. More precisely, the
|
|
225
|
+
return value is self - n * other where n is the integer nearest to
|
|
226
|
+
the exact value of self / other, and if two integers are equally
|
|
227
|
+
near then the even one is chosen.
|
|
222
228
|
|
|
223
229
|
If the result is zero then its sign will be the sign of self.
|
|
224
230
|
"""
|
|
@@ -229,7 +235,9 @@ class Decimal:
|
|
|
229
235
|
def __int__(self) -> int:
|
|
230
236
|
"""int(self)"""
|
|
231
237
|
...
|
|
232
|
-
def __trunc__(self) -> int:
|
|
238
|
+
def __trunc__(self) -> int:
|
|
239
|
+
"""Return the Integral closest to x between 0 and x."""
|
|
240
|
+
...
|
|
233
241
|
@property
|
|
234
242
|
def real(self) -> Decimal: ...
|
|
235
243
|
@property
|
|
@@ -237,19 +245,31 @@ class Decimal:
|
|
|
237
245
|
def conjugate(self) -> Decimal:
|
|
238
246
|
"""Return self."""
|
|
239
247
|
...
|
|
240
|
-
def __complex__(self) -> complex:
|
|
248
|
+
def __complex__(self) -> complex:
|
|
249
|
+
"""Convert this value to exact type complex."""
|
|
250
|
+
...
|
|
241
251
|
|
|
242
252
|
@overload
|
|
243
|
-
def __round__(self) -> int:
|
|
253
|
+
def __round__(self) -> int:
|
|
254
|
+
"""Return the Integral closest to self, rounding half toward even."""
|
|
255
|
+
...
|
|
244
256
|
@overload
|
|
245
|
-
def __round__(self, ndigits: int, /) -> Decimal:
|
|
257
|
+
def __round__(self, ndigits: int, /) -> Decimal:
|
|
258
|
+
"""Return the Integral closest to self, rounding half toward even."""
|
|
259
|
+
...
|
|
246
260
|
|
|
247
|
-
def __floor__(self) -> int:
|
|
248
|
-
|
|
261
|
+
def __floor__(self) -> int:
|
|
262
|
+
"""Return the floor as an Integral."""
|
|
263
|
+
...
|
|
264
|
+
def __ceil__(self) -> int:
|
|
265
|
+
"""Return the ceiling as an Integral."""
|
|
266
|
+
...
|
|
249
267
|
def fma(self, other: _Decimal, third: _Decimal, context: Context | None = None) -> Decimal:
|
|
250
268
|
"""
|
|
251
|
-
Fused multiply-add.
|
|
252
|
-
|
|
269
|
+
Fused multiply-add.
|
|
270
|
+
|
|
271
|
+
Return self*other+third with no rounding of the intermediate product
|
|
272
|
+
self*other.
|
|
253
273
|
|
|
254
274
|
>>> Decimal(2).fma(3, 5)
|
|
255
275
|
Decimal('11')
|
|
@@ -260,92 +280,110 @@ class Decimal:
|
|
|
260
280
|
...
|
|
261
281
|
def normalize(self, context: Context | None = None) -> Decimal:
|
|
262
282
|
"""
|
|
263
|
-
Normalize the number by stripping
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
283
|
+
Normalize the number by stripping trailing 0s
|
|
284
|
+
|
|
285
|
+
This also change anything equal to 0 to 0e0. Used for producing
|
|
286
|
+
canonical values for members of an equivalence class. For example,
|
|
287
|
+
Decimal('32.100') and Decimal('0.321000e+2') both normalize to
|
|
288
|
+
the equivalent value Decimal('32.1').
|
|
268
289
|
"""
|
|
269
290
|
...
|
|
270
291
|
def quantize(self, exp: _Decimal, rounding: str | None = None, context: Context | None = None) -> Decimal:
|
|
271
292
|
"""
|
|
272
|
-
|
|
273
|
-
|
|
293
|
+
Quantize *self* so its exponent is the same as that of *exp*.
|
|
294
|
+
|
|
295
|
+
Return a value equal to *self* after rounding, with the exponent
|
|
296
|
+
of *exp*.
|
|
274
297
|
|
|
275
298
|
>>> Decimal('1.41421356').quantize(Decimal('1.000'))
|
|
276
299
|
Decimal('1.414')
|
|
277
300
|
|
|
278
|
-
Unlike other operations, if the length of the coefficient after the
|
|
279
|
-
operation would be greater than precision, then an
|
|
280
|
-
This guarantees that, unless there
|
|
281
|
-
is
|
|
301
|
+
Unlike other operations, if the length of the coefficient after the
|
|
302
|
+
quantize operation would be greater than precision, then an
|
|
303
|
+
InvalidOperation is signaled. This guarantees that, unless there
|
|
304
|
+
is an error condition, the quantized exponent is always equal to
|
|
305
|
+
that of the right-hand operand.
|
|
282
306
|
|
|
283
|
-
Also unlike other operations, quantize never signals Underflow, even
|
|
284
|
-
result is subnormal and inexact.
|
|
307
|
+
Also unlike other operations, quantize never signals Underflow, even
|
|
308
|
+
if the result is subnormal and inexact.
|
|
285
309
|
|
|
286
|
-
If the exponent of the second operand is larger than that of the
|
|
287
|
-
rounding may be necessary.
|
|
288
|
-
rounding argument if given, else by the
|
|
289
|
-
argument is given, the rounding
|
|
310
|
+
If the exponent of the second operand is larger than that of the
|
|
311
|
+
first, then rounding may be necessary. In this case, the rounding
|
|
312
|
+
mode is determined by the rounding argument if given, else by the
|
|
313
|
+
given context argument; if neither argument is given, the rounding
|
|
314
|
+
mode of the current thread's context is used.
|
|
290
315
|
"""
|
|
291
316
|
...
|
|
292
317
|
def same_quantum(self, other: _Decimal, context: Context | None = None) -> bool:
|
|
293
318
|
"""
|
|
294
|
-
Test whether self and other have the same exponent or
|
|
319
|
+
Test whether self and other have the same exponent or both are NaN.
|
|
295
320
|
|
|
296
|
-
This operation is unaffected by context and is quiet: no flags are
|
|
297
|
-
and no rounding is performed. As an exception, the C version
|
|
298
|
-
InvalidOperation if the second operand cannot be converted
|
|
321
|
+
This operation is unaffected by context and is quiet: no flags are
|
|
322
|
+
changed and no rounding is performed. As an exception, the C version
|
|
323
|
+
may raise InvalidOperation if the second operand cannot be converted
|
|
324
|
+
exactly.
|
|
299
325
|
"""
|
|
300
326
|
...
|
|
301
327
|
def to_integral_exact(self, rounding: str | None = None, context: Context | None = None) -> Decimal:
|
|
302
328
|
"""
|
|
303
|
-
Round to the nearest integer
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
rounding mode
|
|
329
|
+
Round to the nearest integer.
|
|
330
|
+
|
|
331
|
+
This method signals Inexact or Rounded as appropriate if rounding
|
|
332
|
+
occurs. The rounding mode is determined by the rounding parameter
|
|
333
|
+
if given, else by the given context. If neither parameter is given,
|
|
334
|
+
then the rounding mode of the current default context is used.
|
|
307
335
|
"""
|
|
308
336
|
...
|
|
309
337
|
def to_integral_value(self, rounding: str | None = None, context: Context | None = None) -> Decimal:
|
|
310
338
|
"""
|
|
311
|
-
Round to the nearest integer without signaling Inexact or Rounded.
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
339
|
+
Round to the nearest integer without signaling Inexact or Rounded.
|
|
340
|
+
|
|
341
|
+
The rounding mode is determined by the rounding parameter if given,
|
|
342
|
+
else by the given context. If neither parameter is given, then the
|
|
343
|
+
rounding mode of the current default context is used.
|
|
315
344
|
"""
|
|
316
345
|
...
|
|
317
346
|
def to_integral(self, rounding: str | None = None, context: Context | None = None) -> Decimal:
|
|
318
347
|
"""
|
|
319
|
-
Identical to the to_integral_value() method.
|
|
320
|
-
|
|
348
|
+
Identical to the to_integral_value() method.
|
|
349
|
+
|
|
350
|
+
The to_integral() name has been kept for compatibility with older
|
|
351
|
+
versions.
|
|
321
352
|
"""
|
|
322
353
|
...
|
|
323
354
|
def sqrt(self, context: Context | None = None) -> Decimal:
|
|
324
355
|
"""
|
|
325
|
-
Return the square root of the argument to full precision.
|
|
326
|
-
|
|
356
|
+
Return the square root of the argument to full precision.
|
|
357
|
+
|
|
358
|
+
The result is correctly rounded using the ROUND_HALF_EVEN rounding
|
|
359
|
+
mode.
|
|
327
360
|
"""
|
|
328
361
|
...
|
|
329
362
|
def max(self, other: _Decimal, context: Context | None = None) -> Decimal:
|
|
330
363
|
"""
|
|
331
|
-
Maximum of self and other.
|
|
332
|
-
|
|
364
|
+
Maximum of self and other.
|
|
365
|
+
|
|
366
|
+
If one operand is a quiet NaN and the other is numeric, the numeric
|
|
367
|
+
operand is returned.
|
|
333
368
|
"""
|
|
334
369
|
...
|
|
335
370
|
def min(self, other: _Decimal, context: Context | None = None) -> Decimal:
|
|
336
371
|
"""
|
|
337
|
-
Minimum of self and other.
|
|
338
|
-
|
|
372
|
+
Minimum of self and other.
|
|
373
|
+
|
|
374
|
+
If one operand is a quiet NaN and the other is numeric, the numeric
|
|
375
|
+
operand is returned.
|
|
339
376
|
"""
|
|
340
377
|
...
|
|
341
378
|
def adjusted(self) -> int:
|
|
342
|
-
"""Return the adjusted exponent
|
|
379
|
+
"""Return the adjusted exponent (exp + digits - 1) of the number."""
|
|
343
380
|
...
|
|
344
381
|
def canonical(self) -> Decimal:
|
|
345
382
|
"""
|
|
346
|
-
Return the canonical encoding of the argument.
|
|
347
|
-
|
|
348
|
-
|
|
383
|
+
Return the canonical encoding of the argument.
|
|
384
|
+
|
|
385
|
+
Currently, the encoding of a Decimal instance is always canonical,
|
|
386
|
+
so this operation returns its argument unchanged.
|
|
349
387
|
"""
|
|
350
388
|
...
|
|
351
389
|
def compare_signal(self, other: _Decimal, context: Context | None = None) -> Decimal:
|
|
@@ -353,100 +391,103 @@ class Decimal:
|
|
|
353
391
|
...
|
|
354
392
|
def compare_total(self, other: _Decimal, context: Context | None = None) -> Decimal:
|
|
355
393
|
"""
|
|
356
|
-
Compare two operands using their abstract representation
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
in this
|
|
394
|
+
Compare two operands using their abstract representation.
|
|
395
|
+
|
|
396
|
+
Similar to the compare() method, but the result gives a total
|
|
397
|
+
ordering on Decimal instances. Two Decimal instances with the same
|
|
398
|
+
numeric value but different representations compare unequal in this
|
|
399
|
+
ordering:
|
|
361
400
|
|
|
362
401
|
>>> Decimal('12.0').compare_total(Decimal('12'))
|
|
363
402
|
Decimal('-1')
|
|
364
403
|
|
|
365
|
-
Quiet and signaling NaNs are also included in the total ordering.
|
|
366
|
-
of this function is Decimal('0') if both operands have
|
|
367
|
-
Decimal('-1') if the first operand is lower
|
|
368
|
-
and Decimal('1') if the first
|
|
369
|
-
|
|
404
|
+
Quiet and signaling NaNs are also included in the total ordering.
|
|
405
|
+
The result of this function is Decimal('0') if both operands have
|
|
406
|
+
the same representation, Decimal('-1') if the first operand is lower
|
|
407
|
+
in the total order than the second, and Decimal('1') if the first
|
|
408
|
+
operand is higher in the total order than the second operand. See
|
|
409
|
+
the specification for details of the total order.
|
|
370
410
|
|
|
371
|
-
This operation is unaffected by context and is quiet: no flags are
|
|
372
|
-
and no rounding is performed.
|
|
373
|
-
InvalidOperation if the second operand cannot be
|
|
411
|
+
This operation is unaffected by context and is quiet: no flags are
|
|
412
|
+
changed and no rounding is performed. As an exception, the C
|
|
413
|
+
version may raise InvalidOperation if the second operand cannot be
|
|
414
|
+
converted exactly.
|
|
374
415
|
"""
|
|
375
416
|
...
|
|
376
417
|
def compare_total_mag(self, other: _Decimal, context: Context | None = None) -> Decimal:
|
|
377
418
|
"""
|
|
378
|
-
|
|
379
|
-
value as in compare_total(), but ignoring the sign of each operand.
|
|
419
|
+
As compare_total(), but ignores the sign of each operand.
|
|
380
420
|
|
|
381
|
-
x.compare_total_mag(y) is equivalent to
|
|
421
|
+
x.compare_total_mag(y) is equivalent to
|
|
422
|
+
x.copy_abs().compare_total(y.copy_abs()).
|
|
382
423
|
|
|
383
|
-
This operation is unaffected by context and is quiet: no flags are
|
|
384
|
-
and no rounding is performed. As an exception, the C version
|
|
385
|
-
InvalidOperation if the second operand cannot be converted
|
|
424
|
+
This operation is unaffected by context and is quiet: no flags are
|
|
425
|
+
changed and no rounding is performed. As an exception, the C version
|
|
426
|
+
may raise InvalidOperation if the second operand cannot be converted
|
|
427
|
+
exactly.
|
|
386
428
|
"""
|
|
387
429
|
...
|
|
388
430
|
def copy_abs(self) -> Decimal:
|
|
389
431
|
"""
|
|
390
|
-
Return the absolute value of the argument.
|
|
391
|
-
|
|
432
|
+
Return the absolute value of the argument.
|
|
433
|
+
|
|
434
|
+
This operation is unaffected by context and is quiet: no flags are
|
|
435
|
+
changed and no rounding is performed.
|
|
392
436
|
"""
|
|
393
437
|
...
|
|
394
438
|
def copy_negate(self) -> Decimal:
|
|
395
439
|
"""
|
|
396
|
-
Return the negation of the argument.
|
|
397
|
-
|
|
440
|
+
Return the negation of the argument.
|
|
441
|
+
|
|
442
|
+
This operation is unaffected by context and is quiet: no flags are
|
|
443
|
+
changed and no rounding is performed.
|
|
398
444
|
"""
|
|
399
445
|
...
|
|
400
446
|
def copy_sign(self, other: _Decimal, context: Context | None = None) -> Decimal:
|
|
401
447
|
"""
|
|
402
|
-
Return a copy of
|
|
403
|
-
|
|
448
|
+
Return a copy of *self* with the sign of *other*.
|
|
449
|
+
|
|
450
|
+
For example:
|
|
404
451
|
|
|
405
452
|
>>> Decimal('2.3').copy_sign(Decimal('-1.5'))
|
|
406
453
|
Decimal('-2.3')
|
|
407
454
|
|
|
408
|
-
This operation is unaffected by context and is quiet: no flags are
|
|
409
|
-
and no rounding is performed. As an exception, the C version
|
|
410
|
-
InvalidOperation if the second operand cannot be converted
|
|
455
|
+
This operation is unaffected by context and is quiet: no flags are
|
|
456
|
+
changed and no rounding is performed. As an exception, the C version
|
|
457
|
+
may raise InvalidOperation if the second operand cannot be converted
|
|
458
|
+
exactly.
|
|
411
459
|
"""
|
|
412
460
|
...
|
|
413
461
|
def exp(self, context: Context | None = None) -> Decimal:
|
|
414
462
|
"""
|
|
415
|
-
Return the value of the (natural) exponential function e**x
|
|
416
|
-
|
|
417
|
-
|
|
463
|
+
Return the value of the (natural) exponential function e**x.
|
|
464
|
+
|
|
465
|
+
The function always uses the ROUND_HALF_EVEN mode and the result is
|
|
466
|
+
correctly rounded.
|
|
418
467
|
"""
|
|
419
468
|
...
|
|
420
469
|
def is_canonical(self) -> bool:
|
|
421
470
|
"""
|
|
422
|
-
Return True if the argument is canonical and False otherwise.
|
|
423
|
-
|
|
424
|
-
|
|
471
|
+
Return True if the argument is canonical and False otherwise.
|
|
472
|
+
|
|
473
|
+
Currently, a Decimal instance is always canonical, so this operation
|
|
474
|
+
always returns True.
|
|
425
475
|
"""
|
|
426
476
|
...
|
|
427
477
|
def is_finite(self) -> bool:
|
|
428
|
-
"""
|
|
429
|
-
Return True if the argument is a finite number, and False if the argument
|
|
430
|
-
is infinite or a NaN.
|
|
431
|
-
"""
|
|
478
|
+
"""Return True if the argument is a finite number, and False otherwise."""
|
|
432
479
|
...
|
|
433
480
|
def is_infinite(self) -> bool:
|
|
434
|
-
"""
|
|
435
|
-
Return True if the argument is either positive or negative infinity and
|
|
436
|
-
False otherwise.
|
|
437
|
-
"""
|
|
481
|
+
"""Return True if the argument is infinite, and False otherwise."""
|
|
438
482
|
...
|
|
439
483
|
def is_nan(self) -> bool:
|
|
440
|
-
"""
|
|
441
|
-
Return True if the argument is a (quiet or signaling) NaN and False
|
|
442
|
-
otherwise.
|
|
443
|
-
"""
|
|
484
|
+
"""Return True if the argument is a (quiet or signaling) NaN, else False."""
|
|
444
485
|
...
|
|
445
486
|
def is_normal(self, context: Context | None = None) -> bool:
|
|
446
487
|
"""
|
|
447
|
-
Return True if the argument is a normal
|
|
448
|
-
|
|
449
|
-
|
|
488
|
+
Return True if the argument is a normal number and False otherwise.
|
|
489
|
+
|
|
490
|
+
Normal number is a finite nonzero number, which is not subnormal.
|
|
450
491
|
"""
|
|
451
492
|
...
|
|
452
493
|
def is_qnan(self) -> bool:
|
|
@@ -455,6 +496,7 @@ class Decimal:
|
|
|
455
496
|
def is_signed(self) -> bool:
|
|
456
497
|
"""
|
|
457
498
|
Return True if the argument has a negative sign and False otherwise.
|
|
499
|
+
|
|
458
500
|
Note that both zeros and NaNs can carry signs.
|
|
459
501
|
"""
|
|
460
502
|
...
|
|
@@ -463,35 +505,38 @@ class Decimal:
|
|
|
463
505
|
...
|
|
464
506
|
def is_subnormal(self, context: Context | None = None) -> bool:
|
|
465
507
|
"""
|
|
466
|
-
Return True if the argument is subnormal, and False otherwise.
|
|
467
|
-
|
|
468
|
-
|
|
508
|
+
Return True if the argument is subnormal, and False otherwise.
|
|
509
|
+
|
|
510
|
+
A number is subnormal if it is non-zero, finite, and has an adjusted
|
|
511
|
+
exponent less than Emin.
|
|
469
512
|
"""
|
|
470
513
|
...
|
|
471
514
|
def is_zero(self) -> bool:
|
|
472
|
-
"""
|
|
473
|
-
Return True if the argument is a (positive or negative) zero and False
|
|
474
|
-
otherwise.
|
|
475
|
-
"""
|
|
515
|
+
"""Return True if the argument is a zero and False otherwise."""
|
|
476
516
|
...
|
|
477
517
|
def ln(self, context: Context | None = None) -> Decimal:
|
|
478
518
|
"""
|
|
479
|
-
Return the natural (base e) logarithm of the operand.
|
|
480
|
-
|
|
519
|
+
Return the natural (base e) logarithm of the operand.
|
|
520
|
+
|
|
521
|
+
The function always uses the ROUND_HALF_EVEN mode and the result is
|
|
522
|
+
correctly rounded.
|
|
481
523
|
"""
|
|
482
524
|
...
|
|
483
525
|
def log10(self, context: Context | None = None) -> Decimal:
|
|
484
526
|
"""
|
|
485
|
-
Return the base ten logarithm of the operand.
|
|
486
|
-
|
|
527
|
+
Return the base ten logarithm of the operand.
|
|
528
|
+
|
|
529
|
+
The function always uses the ROUND_HALF_EVEN mode and the result is
|
|
530
|
+
correctly rounded.
|
|
487
531
|
"""
|
|
488
532
|
...
|
|
489
533
|
def logb(self, context: Context | None = None) -> Decimal:
|
|
490
534
|
"""
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
535
|
+
Return the adjusted exponent of the operand as a Decimal instance.
|
|
536
|
+
|
|
537
|
+
If the operand is a zero, then Decimal('-Infinity') is returned and
|
|
538
|
+
the DivisionByZero condition is raised. If the operand is an
|
|
539
|
+
infinity then Decimal('Infinity') is returned.
|
|
495
540
|
"""
|
|
496
541
|
...
|
|
497
542
|
def logical_and(self, other: _Decimal, context: Context | None = None) -> Decimal:
|
|
@@ -512,7 +557,7 @@ class Decimal:
|
|
|
512
557
|
"""
|
|
513
558
|
Applies an 'or' operation between self and other's digits.
|
|
514
559
|
|
|
515
|
-
Both self and other must be logical numbers.
|
|
560
|
+
Both self and other must be logical numbers.
|
|
516
561
|
"""
|
|
517
562
|
...
|
|
518
563
|
def logical_xor(self, other: _Decimal, context: Context | None = None) -> Decimal:
|
|
@@ -523,96 +568,99 @@ class Decimal:
|
|
|
523
568
|
"""
|
|
524
569
|
...
|
|
525
570
|
def max_mag(self, other: _Decimal, context: Context | None = None) -> Decimal:
|
|
526
|
-
"""
|
|
527
|
-
Similar to the max() method, but the comparison is done using the absolute
|
|
528
|
-
values of the operands.
|
|
529
|
-
"""
|
|
571
|
+
"""As the max() method, but compares the absolute values of the operands."""
|
|
530
572
|
...
|
|
531
573
|
def min_mag(self, other: _Decimal, context: Context | None = None) -> Decimal:
|
|
532
|
-
"""
|
|
533
|
-
Similar to the min() method, but the comparison is done using the absolute
|
|
534
|
-
values of the operands.
|
|
535
|
-
"""
|
|
574
|
+
"""As the min() method, but compares the absolute values of the operands."""
|
|
536
575
|
...
|
|
537
576
|
def next_minus(self, context: Context | None = None) -> Decimal:
|
|
538
|
-
"""
|
|
539
|
-
Return the largest number representable in the given context (or in the
|
|
540
|
-
current default context if no context is given) that is smaller than the
|
|
541
|
-
given operand.
|
|
542
|
-
"""
|
|
577
|
+
"""Returns the largest representable number smaller than itself."""
|
|
543
578
|
...
|
|
544
579
|
def next_plus(self, context: Context | None = None) -> Decimal:
|
|
545
|
-
"""
|
|
546
|
-
Return the smallest number representable in the given context (or in the
|
|
547
|
-
current default context if no context is given) that is larger than the
|
|
548
|
-
given operand.
|
|
549
|
-
"""
|
|
580
|
+
"""Returns the smallest representable number larger than itself."""
|
|
550
581
|
...
|
|
551
582
|
def next_toward(self, other: _Decimal, context: Context | None = None) -> Decimal:
|
|
552
583
|
"""
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
584
|
+
Returns the number closest to self, in the direction towards other.
|
|
585
|
+
|
|
586
|
+
If the two operands are unequal, return the number closest to the
|
|
587
|
+
first operand in the direction of the second operand. If both
|
|
588
|
+
operands are numerically equal, return a copy of the first operand
|
|
589
|
+
with the sign set to be the same as the sign of the second operand.
|
|
557
590
|
"""
|
|
558
591
|
...
|
|
559
592
|
def number_class(self, context: Context | None = None) -> str:
|
|
560
593
|
"""
|
|
561
|
-
Return a string describing the class of the operand.
|
|
562
|
-
|
|
594
|
+
Return a string describing the class of the operand.
|
|
595
|
+
|
|
596
|
+
The returned value is one of the following ten strings:
|
|
563
597
|
|
|
564
598
|
* '-Infinity', indicating that the operand is negative infinity.
|
|
565
|
-
* '-Normal', indicating that the operand is a negative normal
|
|
566
|
-
|
|
599
|
+
* '-Normal', indicating that the operand is a negative normal
|
|
600
|
+
number.
|
|
601
|
+
* '-Subnormal', indicating that the operand is negative and
|
|
602
|
+
subnormal.
|
|
567
603
|
* '-Zero', indicating that the operand is a negative zero.
|
|
568
604
|
* '+Zero', indicating that the operand is a positive zero.
|
|
569
|
-
* '+Subnormal', indicating that the operand is positive and
|
|
570
|
-
|
|
605
|
+
* '+Subnormal', indicating that the operand is positive and
|
|
606
|
+
subnormal.
|
|
607
|
+
* '+Normal', indicating that the operand is a positive normal
|
|
608
|
+
number.
|
|
571
609
|
* '+Infinity', indicating that the operand is positive infinity.
|
|
572
|
-
* 'NaN', indicating that the operand is a quiet NaN (Not a
|
|
610
|
+
* 'NaN', indicating that the operand is a quiet NaN (Not a
|
|
611
|
+
Number).
|
|
573
612
|
* 'sNaN', indicating that the operand is a signaling NaN.
|
|
574
613
|
"""
|
|
575
614
|
...
|
|
576
615
|
def radix(self) -> Decimal:
|
|
577
616
|
"""
|
|
578
|
-
Return Decimal(10)
|
|
579
|
-
|
|
617
|
+
Return Decimal(10).
|
|
618
|
+
|
|
619
|
+
This is the radix (base) in which the Decimal class does all its
|
|
620
|
+
arithmetic. Included for compatibility with the specification.
|
|
580
621
|
"""
|
|
581
622
|
...
|
|
582
623
|
def rotate(self, other: _Decimal, context: Context | None = None) -> Decimal:
|
|
583
624
|
"""
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
625
|
+
Returns a rotated copy of self's digits, value-of-other times.
|
|
626
|
+
|
|
627
|
+
The second operand must be an integer in the range -precision
|
|
628
|
+
through precision. The absolute value of the second operand gives
|
|
629
|
+
the number of places to rotate. If the second operand is positive
|
|
630
|
+
then rotation is to the left; otherwise rotation is to the right.
|
|
631
|
+
The coefficient of the first operand is padded on the left with
|
|
632
|
+
zeros to length precision if necessary. The sign and exponent of
|
|
633
|
+
the first operand are unchanged.
|
|
592
634
|
"""
|
|
593
635
|
...
|
|
594
636
|
def scaleb(self, other: _Decimal, context: Context | None = None) -> Decimal:
|
|
595
637
|
"""
|
|
596
|
-
Return the first operand with the exponent adjusted the second.
|
|
597
|
-
|
|
598
|
-
|
|
638
|
+
Return the first operand with the exponent adjusted the second.
|
|
639
|
+
|
|
640
|
+
Equivalently, return the first operand multiplied by 10**other. The
|
|
641
|
+
second operand must be an integer.
|
|
599
642
|
"""
|
|
600
643
|
...
|
|
601
644
|
def shift(self, other: _Decimal, context: Context | None = None) -> Decimal:
|
|
602
645
|
"""
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
646
|
+
Returns a shifted copy of self's digits, value-of-other times.
|
|
647
|
+
|
|
648
|
+
The second operand must be an integer in the range -precision
|
|
649
|
+
through precision. The absolute value of the second operand gives
|
|
650
|
+
the number of places to shift. If the second operand is positive,
|
|
651
|
+
then the shift is to the left; otherwise the shift is to the right.
|
|
652
|
+
Digits shifted into the coefficient are zeros. The sign and
|
|
653
|
+
exponent of the first operand are unchanged.
|
|
610
654
|
"""
|
|
611
655
|
...
|
|
612
|
-
def __reduce__(self) -> tuple[type[Self], tuple[str]]:
|
|
656
|
+
def __reduce__(self) -> tuple[type[Self], tuple[str]]:
|
|
657
|
+
"""Return state information for pickling."""
|
|
658
|
+
...
|
|
613
659
|
def __copy__(self) -> Self: ...
|
|
614
660
|
def __deepcopy__(self, memo: Any, /) -> Self: ...
|
|
615
|
-
def __format__(self, specifier: str, context: Context | None = None, /) -> str:
|
|
661
|
+
def __format__(self, specifier: str, context: Context | None = None, /) -> str:
|
|
662
|
+
"""Formats the Decimal according to format_spec."""
|
|
663
|
+
...
|
|
616
664
|
|
|
617
665
|
@disjoint_base
|
|
618
666
|
class Context:
|
|
@@ -655,27 +703,34 @@ class Context:
|
|
|
655
703
|
__hash__: ClassVar[None] # type: ignore[assignment]
|
|
656
704
|
def Etiny(self) -> int:
|
|
657
705
|
"""
|
|
658
|
-
Return a value equal to Emin - prec + 1
|
|
659
|
-
|
|
706
|
+
Return a value equal to Emin - prec + 1.
|
|
707
|
+
|
|
708
|
+
This is the minimum exponent value for subnormal results. When
|
|
709
|
+
underflow occurs, the exponent is set to Etiny.
|
|
660
710
|
"""
|
|
661
711
|
...
|
|
662
712
|
def Etop(self) -> int:
|
|
663
713
|
"""
|
|
664
|
-
Return a value equal to Emax - prec + 1.
|
|
665
|
-
|
|
666
|
-
|
|
714
|
+
Return a value equal to Emax - prec + 1.
|
|
715
|
+
|
|
716
|
+
This is the maximum exponent if the _clamp field of the context is
|
|
717
|
+
set to 1 (IEEE clamp mode). Etop() must not be negative.
|
|
667
718
|
"""
|
|
668
719
|
...
|
|
669
720
|
def create_decimal(self, num: _DecimalNew = "0", /) -> Decimal:
|
|
670
721
|
"""
|
|
671
|
-
Create a new Decimal instance from num, using self as the context.
|
|
672
|
-
|
|
722
|
+
Create a new Decimal instance from num, using self as the context.
|
|
723
|
+
|
|
724
|
+
Unlike the Decimal constructor, this function observes the context
|
|
725
|
+
limits.
|
|
673
726
|
"""
|
|
674
727
|
...
|
|
675
728
|
def create_decimal_from_float(self, f: float, /) -> Decimal:
|
|
676
729
|
"""
|
|
677
|
-
Create a new Decimal instance from float f.
|
|
678
|
-
|
|
730
|
+
Create a new Decimal instance from float f.
|
|
731
|
+
|
|
732
|
+
Unlike the Decimal.from_float() class method, this function observes
|
|
733
|
+
the context limits.
|
|
679
734
|
"""
|
|
680
735
|
...
|
|
681
736
|
def abs(self, x: _Decimal, /) -> Decimal:
|
|
@@ -875,8 +930,9 @@ class Context:
|
|
|
875
930
|
...
|
|
876
931
|
def minus(self, x: _Decimal, /) -> Decimal:
|
|
877
932
|
"""
|
|
878
|
-
Minus corresponds to
|
|
879
|
-
|
|
933
|
+
Minus corresponds to unary prefix minus in Python.
|
|
934
|
+
|
|
935
|
+
This operation applies the context to the result.
|
|
880
936
|
"""
|
|
881
937
|
...
|
|
882
938
|
def multiply(self, x: _Decimal, y: _Decimal, /) -> Decimal:
|
|
@@ -899,25 +955,29 @@ class Context:
|
|
|
899
955
|
...
|
|
900
956
|
def plus(self, x: _Decimal, /) -> Decimal:
|
|
901
957
|
"""
|
|
902
|
-
Plus corresponds to the unary prefix plus operator in Python
|
|
903
|
-
|
|
958
|
+
Plus corresponds to the unary prefix plus operator in Python.
|
|
959
|
+
|
|
960
|
+
This operation applies the context to the result.
|
|
904
961
|
"""
|
|
905
962
|
...
|
|
906
963
|
def power(self, a: _Decimal, b: _Decimal, modulo: _Decimal | None = None) -> Decimal:
|
|
907
964
|
"""
|
|
908
|
-
Compute a**b.
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
965
|
+
Compute a**b.
|
|
966
|
+
|
|
967
|
+
If 'a' is negative, then 'b' must be integral. The result will be
|
|
968
|
+
inexact unless 'a' is integral and the result is finite and can be
|
|
969
|
+
expressed exactly in 'precision' digits. In the Python version the
|
|
970
|
+
result is always correctly rounded, in the C version the result is
|
|
971
|
+
almost always correctly rounded.
|
|
913
972
|
|
|
914
|
-
If modulo is given, compute (a**b) % modulo. The following
|
|
915
|
-
hold:
|
|
973
|
+
If modulo is given, compute (a**b) % modulo. The following
|
|
974
|
+
restrictions hold:
|
|
916
975
|
|
|
917
976
|
* all three arguments must be integral
|
|
918
977
|
* 'b' must be nonnegative
|
|
919
978
|
* at least one of 'a' or 'b' must be nonzero
|
|
920
|
-
* modulo must be nonzero and less than 10**prec in absolute
|
|
979
|
+
* modulo must be nonzero and less than 10**prec in absolute
|
|
980
|
+
value
|
|
921
981
|
"""
|
|
922
982
|
...
|
|
923
983
|
def quantize(self, x: _Decimal, y: _Decimal, /) -> Decimal:
|
|
@@ -928,14 +988,18 @@ class Context:
|
|
|
928
988
|
...
|
|
929
989
|
def remainder(self, x: _Decimal, y: _Decimal, /) -> Decimal:
|
|
930
990
|
"""
|
|
931
|
-
Return the remainder from integer division.
|
|
932
|
-
|
|
991
|
+
Return the remainder from integer division.
|
|
992
|
+
|
|
993
|
+
The sign of the result, if non-zero, is the same as that of the
|
|
994
|
+
original dividend.
|
|
933
995
|
"""
|
|
934
996
|
...
|
|
935
997
|
def remainder_near(self, x: _Decimal, y: _Decimal, /) -> Decimal:
|
|
936
998
|
"""
|
|
937
|
-
Return x - y * n
|
|
938
|
-
|
|
999
|
+
Return x - y * n.
|
|
1000
|
+
|
|
1001
|
+
Here n is the integer nearest the exact value of x / y (if the
|
|
1002
|
+
result is 0 then its sign will be the sign of x).
|
|
939
1003
|
"""
|
|
940
1004
|
...
|
|
941
1005
|
def rotate(self, x: _Decimal, y: _Decimal, /) -> Decimal:
|