mirror of
https://github.com/python/cpython.git
synced 2025-07-29 06:05:00 +00:00
Made the various is_* operations return booleans. This was discussed
with Cawlishaw by mail, and he basically confirmed that to these is_* operations, there's no need to return Decimal(0) and Decimal(1) if the language supports the False and True booleans. Also added a few tests for the these functions in extra.decTest, since they are mostly untested (apart from the doctests). Thanks Mark Dickinson
This commit is contained in:
parent
31ba8480d8
commit
1a191df14d
3 changed files with 2240 additions and 125 deletions
|
@ -95,35 +95,61 @@ RoundingDict = {'ceiling' : ROUND_CEILING, #Maps test-case names to roundings.
|
|||
|
||||
# Name adapter to be able to change the Decimal and Context
|
||||
# interface without changing the test files from Cowlishaw
|
||||
nameAdapter = {'toeng':'to_eng_string',
|
||||
'tosci':'to_sci_string',
|
||||
'samequantum':'same_quantum',
|
||||
'tointegral':'to_integral_value',
|
||||
'tointegralx':'to_integral_exact',
|
||||
'remaindernear':'remainder_near',
|
||||
'divideint':'divide_int',
|
||||
'squareroot':'sqrt',
|
||||
nameAdapter = {'and':'logical_and',
|
||||
'apply':'_apply',
|
||||
'class':'number_class',
|
||||
'comparesig':'compare_signal',
|
||||
'comparetotal':'compare_total',
|
||||
'comparetotmag':'compare_total_mag',
|
||||
'copyabs':'copy_abs',
|
||||
'copy':'copy_decimal',
|
||||
'copyabs':'copy_abs',
|
||||
'copynegate':'copy_negate',
|
||||
'copysign':'copy_sign',
|
||||
'and':'logical_and',
|
||||
'or':'logical_or',
|
||||
'xor':'logical_xor',
|
||||
'divideint':'divide_int',
|
||||
'invert':'logical_invert',
|
||||
'iscanonical':'is_canonical',
|
||||
'isfinite':'is_finite',
|
||||
'isinfinite':'is_infinite',
|
||||
'isnan':'is_nan',
|
||||
'isnormal':'is_normal',
|
||||
'isqnan':'is_qnan',
|
||||
'issigned':'is_signed',
|
||||
'issnan':'is_snan',
|
||||
'issubnormal':'is_subnormal',
|
||||
'iszero':'is_zero',
|
||||
'maxmag':'max_mag',
|
||||
'minmag':'min_mag',
|
||||
'nextminus':'next_minus',
|
||||
'nextplus':'next_plus',
|
||||
'nexttoward':'next_toward',
|
||||
'or':'logical_or',
|
||||
'reduce':'normalize',
|
||||
'remaindernear':'remainder_near',
|
||||
'samequantum':'same_quantum',
|
||||
'squareroot':'sqrt',
|
||||
'toeng':'to_eng_string',
|
||||
'tointegral':'to_integral_value',
|
||||
'tointegralx':'to_integral_exact',
|
||||
'tosci':'to_sci_string',
|
||||
'xor':'logical_xor',
|
||||
}
|
||||
|
||||
# The following functions return True/False rather than a Decimal instance
|
||||
|
||||
LOGICAL_FUNCTIONS = (
|
||||
'is_canonical',
|
||||
'is_finite',
|
||||
'is_infinite',
|
||||
'is_nan',
|
||||
'is_normal',
|
||||
'is_qnan',
|
||||
'is_signed',
|
||||
'is_snan',
|
||||
'is_subnormal',
|
||||
'is_zero',
|
||||
'same_quantum',
|
||||
)
|
||||
|
||||
# For some operations (currently exp, ln, log10, power), the decNumber
|
||||
# reference implementation imposes additional restrictions on the
|
||||
# context and operands. These restrictions are not part of the
|
||||
|
@ -321,7 +347,7 @@ class DecimalTest(unittest.TestCase):
|
|||
print "--", self.context
|
||||
try:
|
||||
result = str(funct(*vals))
|
||||
if fname == 'same_quantum':
|
||||
if fname in LOGICAL_FUNCTIONS:
|
||||
result = str(int(eval(result))) # 'True', 'False' -> '1', '0'
|
||||
except Signals, error:
|
||||
self.fail("Raised %s in %s" % (error, s))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue