source
stringclasses 2
values | version
stringclasses 2
values | module
stringclasses 53
values | function
stringclasses 318
values | input
stringlengths 3
496
| expected
stringlengths 0
876
| signature
stringclasses 41
values |
|---|---|---|---|---|---|---|
cpython
|
3.10
|
_pydecimal
|
__module__
|
>>> Decimal(123456)
|
Decimal('123456')
| null |
cpython
|
3.10
|
_pydecimal
|
__module__
|
>>> Decimal('123.45e12345678')
|
Decimal('1.2345E+12345680')
| null |
cpython
|
3.10
|
_pydecimal
|
__module__
|
>>> Decimal('1.33') + Decimal('1.27')
|
Decimal('2.60')
| null |
cpython
|
3.10
|
_pydecimal
|
__module__
|
>>> Decimal('12.34') + Decimal('3.87') - Decimal('18.41')
|
Decimal('-2.20')
| null |
cpython
|
3.10
|
_pydecimal
|
__module__
|
>>> dig = Decimal(1)
| null |
|
cpython
|
3.10
|
_pydecimal
|
__module__
|
>>> print(dig / Decimal(3))
|
0.333333333
| null |
cpython
|
3.10
|
_pydecimal
|
__module__
|
>>> getcontext().prec = 18
| null |
|
cpython
|
3.10
|
_pydecimal
|
__module__
|
>>> print(dig / Decimal(3))
|
0.333333333333333333
| null |
cpython
|
3.10
|
_pydecimal
|
__module__
|
>>> print(dig.sqrt())
|
1
| null |
cpython
|
3.10
|
_pydecimal
|
__module__
|
>>> print(Decimal(3).sqrt())
|
1.73205080756887729
| null |
cpython
|
3.10
|
_pydecimal
|
__module__
|
>>> print(Decimal(3) ** 123)
|
4.85192780976896427E+58
| null |
cpython
|
3.10
|
_pydecimal
|
__module__
|
>>> inf = Decimal(1) / Decimal(0)
| null |
|
cpython
|
3.10
|
_pydecimal
|
__module__
|
>>> print(inf)
|
Infinity
| null |
cpython
|
3.10
|
_pydecimal
|
__module__
|
>>> neginf = Decimal(-1) / Decimal(0)
| null |
|
cpython
|
3.10
|
_pydecimal
|
__module__
|
>>> print(neginf)
|
-Infinity
| null |
cpython
|
3.10
|
_pydecimal
|
__module__
|
>>> print(neginf + inf)
|
NaN
| null |
cpython
|
3.10
|
_pydecimal
|
__module__
|
>>> print(neginf * inf)
|
-Infinity
| null |
cpython
|
3.10
|
_pydecimal
|
__module__
|
>>> print(dig / 0)
|
Infinity
| null |
cpython
|
3.10
|
_pydecimal
|
__module__
|
>>> getcontext().traps[DivisionByZero] = 1
| null |
|
cpython
|
3.10
|
_pydecimal
|
__module__
|
>>> print(dig / 0)
|
Traceback (most recent call last):
...
...
...
decimal.DivisionByZero: x / 0
| null |
cpython
|
3.10
|
_pydecimal
|
__module__
|
>>> c = Context()
| null |
|
cpython
|
3.10
|
_pydecimal
|
__module__
|
>>> c.traps[InvalidOperation] = 0
| null |
|
cpython
|
3.10
|
_pydecimal
|
__module__
|
>>> print(c.flags[InvalidOperation])
|
0
| null |
cpython
|
3.10
|
_pydecimal
|
__module__
|
>>> c.divide(Decimal(0), Decimal(0))
|
Decimal('NaN')
| null |
cpython
|
3.10
|
_pydecimal
|
__module__
|
>>> c.traps[InvalidOperation] = 1
| null |
|
cpython
|
3.10
|
_pydecimal
|
__module__
|
>>> print(c.flags[InvalidOperation])
|
1
| null |
cpython
|
3.10
|
_pydecimal
|
__module__
|
>>> c.flags[InvalidOperation] = 0
| null |
|
cpython
|
3.10
|
_pydecimal
|
__module__
|
>>> print(c.flags[InvalidOperation])
|
0
| null |
cpython
|
3.10
|
_pydecimal
|
__module__
|
>>> print(c.divide(Decimal(0), Decimal(0)))
|
Traceback (most recent call last):
...
...
...
decimal.InvalidOperation: 0 / 0
| null |
cpython
|
3.10
|
_pydecimal
|
__module__
|
>>> print(c.flags[InvalidOperation])
|
1
| null |
cpython
|
3.10
|
_pydecimal
|
__module__
|
>>> c.flags[InvalidOperation] = 0
| null |
|
cpython
|
3.10
|
_pydecimal
|
__module__
|
>>> c.traps[InvalidOperation] = 0
| null |
|
cpython
|
3.10
|
_pydecimal
|
__module__
|
>>> print(c.divide(Decimal(0), Decimal(0)))
|
NaN
| null |
cpython
|
3.10
|
_pydecimal
|
__module__
|
>>> print(c.flags[InvalidOperation])
|
1
| null |
cpython
|
3.10
|
_pydecimal
|
__module__
|
>>>
| null |
|
cpython
|
3.10
|
_pydecimal
|
FloatOperation.localcontext
|
>>> setcontext(DefaultContext)
| null |
|
cpython
|
3.10
|
_pydecimal
|
FloatOperation.localcontext
|
>>> print(getcontext().prec)
|
28
| null |
cpython
|
3.10
|
_pydecimal
|
FloatOperation.localcontext
|
>>> with localcontext():
... ctx = getcontext()
... ctx.prec += 2
... print(ctx.prec)
...
|
30
| null |
cpython
|
3.10
|
_pydecimal
|
FloatOperation.localcontext
|
>>> with localcontext(ExtendedContext):
... print(getcontext().prec)
...
|
9
| null |
cpython
|
3.10
|
_pydecimal
|
FloatOperation.localcontext
|
>>> print(getcontext().prec)
|
28
| null |
cpython
|
3.10
|
_pydecimal
|
Decimal.__new__
|
>>> Decimal('3.14') # string input
|
Decimal('3.14')
| null |
cpython
|
3.10
|
_pydecimal
|
Decimal.__new__
|
>>> Decimal((0, (3, 1, 4), -2)) # tuple (sign, digit_tuple, exponent)
|
Decimal('3.14')
| null |
cpython
|
3.10
|
_pydecimal
|
Decimal.__new__
|
>>> Decimal(314) # int
|
Decimal('314')
| null |
cpython
|
3.10
|
_pydecimal
|
Decimal.__new__
|
>>> Decimal(Decimal(314)) # another decimal instance
|
Decimal('314')
| null |
cpython
|
3.10
|
_pydecimal
|
Decimal.__new__
|
>>> Decimal(' 3.14 \\n') # leading and trailing whitespace okay
|
Decimal('3.14')
| null |
cpython
|
3.10
|
_pydecimal
|
Decimal.from_float
|
>>> Decimal.from_float(0.1)
|
Decimal('0.1000000000000000055511151231257827021181583404541015625')
| null |
cpython
|
3.10
|
_pydecimal
|
Decimal.from_float
|
>>> Decimal.from_float(float('nan'))
|
Decimal('NaN')
| null |
cpython
|
3.10
|
_pydecimal
|
Decimal.from_float
|
>>> Decimal.from_float(float('inf'))
|
Decimal('Infinity')
| null |
cpython
|
3.10
|
_pydecimal
|
Decimal.from_float
|
>>> Decimal.from_float(-float('inf'))
|
Decimal('-Infinity')
| null |
cpython
|
3.10
|
_pydecimal
|
Decimal.from_float
|
>>> Decimal.from_float(-0.0)
|
Decimal('-0')
| null |
cpython
|
3.10
|
_pydecimal
|
Decimal.as_integer_ratio
|
>>> Decimal('3.14').as_integer_ratio()
|
(157, 50)
| null |
cpython
|
3.10
|
_pydecimal
|
Decimal.as_integer_ratio
|
>>> Decimal('-123e5').as_integer_ratio()
|
(-12300000, 1)
| null |
cpython
|
3.10
|
_pydecimal
|
Decimal.as_integer_ratio
|
>>> Decimal('0.00').as_integer_ratio()
|
(0, 1)
| null |
cpython
|
3.10
|
_pydecimal
|
Decimal.__round__
|
>>> round(Decimal('123.456'))
|
123
| null |
cpython
|
3.10
|
_pydecimal
|
Decimal.__round__
|
>>> round(Decimal('-456.789'))
|
-457
| null |
cpython
|
3.10
|
_pydecimal
|
Decimal.__round__
|
>>> round(Decimal('-3.0'))
|
-3
| null |
cpython
|
3.10
|
_pydecimal
|
Decimal.__round__
|
>>> round(Decimal('2.5'))
|
2
| null |
cpython
|
3.10
|
_pydecimal
|
Decimal.__round__
|
>>> round(Decimal('3.5'))
|
4
| null |
cpython
|
3.10
|
_pydecimal
|
Decimal.__round__
|
>>> round(Decimal('Inf'))
|
Traceback (most recent call last):
...
OverflowError: cannot round an infinity
| null |
cpython
|
3.10
|
_pydecimal
|
Decimal.__round__
|
>>> round(Decimal('NaN'))
|
Traceback (most recent call last):
...
ValueError: cannot round a NaN
| null |
cpython
|
3.10
|
_pydecimal
|
Decimal.__round__
|
>>> round(Decimal('123.456'), 0)
|
Decimal('123')
| null |
cpython
|
3.10
|
_pydecimal
|
Decimal.__round__
|
>>> round(Decimal('123.456'), 2)
|
Decimal('123.46')
| null |
cpython
|
3.10
|
_pydecimal
|
Decimal.__round__
|
>>> round(Decimal('123.456'), -2)
|
Decimal('1E+2')
| null |
cpython
|
3.10
|
_pydecimal
|
Decimal.__round__
|
>>> round(Decimal('-Infinity'), 37)
|
Decimal('NaN')
| null |
cpython
|
3.10
|
_pydecimal
|
Decimal.__round__
|
>>> round(Decimal('sNaN123'), 0)
|
Decimal('NaN123')
| null |
cpython
|
3.10
|
_pydecimal
|
Context.create_decimal_from_float
|
>>> context = Context(prec=5, rounding=ROUND_DOWN)
| null |
|
cpython
|
3.10
|
_pydecimal
|
Context.create_decimal_from_float
|
>>> context.create_decimal_from_float(3.1415926535897932)
|
Decimal('3.1415')
| null |
cpython
|
3.10
|
_pydecimal
|
Context.create_decimal_from_float
|
>>> context = Context(prec=5, traps=[Inexact])
| null |
|
cpython
|
3.10
|
_pydecimal
|
Context.create_decimal_from_float
|
>>> context.create_decimal_from_float(3.1415926535897932)
|
Traceback (most recent call last):
...
decimal.Inexact: None
| null |
cpython
|
3.10
|
_pydecimal
|
Context.abs
|
>>> ExtendedContext.abs(Decimal('2.1'))
|
Decimal('2.1')
| null |
cpython
|
3.10
|
_pydecimal
|
Context.abs
|
>>> ExtendedContext.abs(Decimal('-100'))
|
Decimal('100')
| null |
cpython
|
3.10
|
_pydecimal
|
Context.abs
|
>>> ExtendedContext.abs(Decimal('101.5'))
|
Decimal('101.5')
| null |
cpython
|
3.10
|
_pydecimal
|
Context.abs
|
>>> ExtendedContext.abs(Decimal('-101.5'))
|
Decimal('101.5')
| null |
cpython
|
3.10
|
_pydecimal
|
Context.abs
|
>>> ExtendedContext.abs(-1)
|
Decimal('1')
| null |
cpython
|
3.10
|
_pydecimal
|
Context.add
|
>>> ExtendedContext.add(Decimal('12'), Decimal('7.00'))
|
Decimal('19.00')
| null |
cpython
|
3.10
|
_pydecimal
|
Context.add
|
>>> ExtendedContext.add(Decimal('1E+2'), Decimal('1.01E+4'))
|
Decimal('1.02E+4')
| null |
cpython
|
3.10
|
_pydecimal
|
Context.add
|
>>> ExtendedContext.add(1, Decimal(2))
|
Decimal('3')
| null |
cpython
|
3.10
|
_pydecimal
|
Context.add
|
>>> ExtendedContext.add(Decimal(8), 5)
|
Decimal('13')
| null |
cpython
|
3.10
|
_pydecimal
|
Context.add
|
>>> ExtendedContext.add(5, 5)
|
Decimal('10')
| null |
cpython
|
3.10
|
_pydecimal
|
Context.canonical
|
>>> ExtendedContext.canonical(Decimal('2.50'))
|
Decimal('2.50')
| null |
cpython
|
3.10
|
_pydecimal
|
Context.compare
|
>>> ExtendedContext.compare(Decimal('2.1'), Decimal('3'))
|
Decimal('-1')
| null |
cpython
|
3.10
|
_pydecimal
|
Context.compare
|
>>> ExtendedContext.compare(Decimal('2.1'), Decimal('2.1'))
|
Decimal('0')
| null |
cpython
|
3.10
|
_pydecimal
|
Context.compare
|
>>> ExtendedContext.compare(Decimal('2.1'), Decimal('2.10'))
|
Decimal('0')
| null |
cpython
|
3.10
|
_pydecimal
|
Context.compare
|
>>> ExtendedContext.compare(Decimal('3'), Decimal('2.1'))
|
Decimal('1')
| null |
cpython
|
3.10
|
_pydecimal
|
Context.compare
|
>>> ExtendedContext.compare(Decimal('2.1'), Decimal('-3'))
|
Decimal('1')
| null |
cpython
|
3.10
|
_pydecimal
|
Context.compare
|
>>> ExtendedContext.compare(Decimal('-3'), Decimal('2.1'))
|
Decimal('-1')
| null |
cpython
|
3.10
|
_pydecimal
|
Context.compare
|
>>> ExtendedContext.compare(1, 2)
|
Decimal('-1')
| null |
cpython
|
3.10
|
_pydecimal
|
Context.compare
|
>>> ExtendedContext.compare(Decimal(1), 2)
|
Decimal('-1')
| null |
cpython
|
3.10
|
_pydecimal
|
Context.compare
|
>>> ExtendedContext.compare(1, Decimal(2))
|
Decimal('-1')
| null |
cpython
|
3.10
|
_pydecimal
|
Context.compare_signal
|
>>> c = ExtendedContext
| null |
|
cpython
|
3.10
|
_pydecimal
|
Context.compare_signal
|
>>> c.compare_signal(Decimal('2.1'), Decimal('3'))
|
Decimal('-1')
| null |
cpython
|
3.10
|
_pydecimal
|
Context.compare_signal
|
>>> c.compare_signal(Decimal('2.1'), Decimal('2.1'))
|
Decimal('0')
| null |
cpython
|
3.10
|
_pydecimal
|
Context.compare_signal
|
>>> c.flags[InvalidOperation] = 0
| null |
|
cpython
|
3.10
|
_pydecimal
|
Context.compare_signal
|
>>> print(c.flags[InvalidOperation])
|
0
| null |
cpython
|
3.10
|
_pydecimal
|
Context.compare_signal
|
>>> c.compare_signal(Decimal('NaN'), Decimal('2.1'))
|
Decimal('NaN')
| null |
cpython
|
3.10
|
_pydecimal
|
Context.compare_signal
|
>>> print(c.flags[InvalidOperation])
|
1
| null |
cpython
|
3.10
|
_pydecimal
|
Context.compare_signal
|
>>> c.flags[InvalidOperation] = 0
| null |
|
cpython
|
3.10
|
_pydecimal
|
Context.compare_signal
|
>>> print(c.flags[InvalidOperation])
|
0
| null |
cpython
|
3.10
|
_pydecimal
|
Context.compare_signal
|
>>> c.compare_signal(Decimal('sNaN'), Decimal('2.1'))
|
Decimal('NaN')
| null |
cpython
|
3.10
|
_pydecimal
|
Context.compare_signal
|
>>> print(c.flags[InvalidOperation])
|
1
| null |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.