MCPcopy Index your code
hub / github.com/python/cpython / IEEEContext

Function IEEEContext

Lib/_pydecimal.py:425–443  ·  view source on GitHub ↗

Return a context object initialized to the proper values for one of the IEEE interchange formats. The argument must be a multiple of 32 and less than IEEE_CONTEXT_MAX_BITS.

(bits, /)

Source from the content-addressed store, hash-verified

423
424
425def IEEEContext(bits, /):
426 """
427 Return a context object initialized to the proper values for one of the
428 IEEE interchange formats. The argument must be a multiple of 32 and less
429 than IEEE_CONTEXT_MAX_BITS.
430 """
431 if bits <= 0 or bits > IEEE_CONTEXT_MAX_BITS or bits % 32:
432 raise ValueError("argument must be a multiple of 32, "
433 f"with a maximum of {IEEE_CONTEXT_MAX_BITS}")
434
435 ctx = Context()
436 ctx.prec = 9 * (bits//32) - 2
437 ctx.Emax = 3 * (1 << (bits//16 + 3))
438 ctx.Emin = 1 - ctx.Emax
439 ctx.rounding = ROUND_HALF_EVEN
440 ctx.clamp = 1
441 ctx.traps = dict.fromkeys(_signals, False)
442
443 return ctx
444
445
446##### Decimal class #######################################################

Callers 1

test_ieee_contextMethod · 0.85

Calls 2

ContextClass · 0.70
fromkeysMethod · 0.45

Tested by 1

test_ieee_contextMethod · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…