Kaydet (Commit) 1a191df1 authored tarafından Facundo Batista's avatar Facundo Batista

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
üst 31ba8480
This diff is collapsed.
...@@ -95,35 +95,61 @@ RoundingDict = {'ceiling' : ROUND_CEILING, #Maps test-case names to roundings. ...@@ -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 # Name adapter to be able to change the Decimal and Context
# interface without changing the test files from Cowlishaw # interface without changing the test files from Cowlishaw
nameAdapter = {'toeng':'to_eng_string', nameAdapter = {'and':'logical_and',
'tosci':'to_sci_string',
'samequantum':'same_quantum',
'tointegral':'to_integral_value',
'tointegralx':'to_integral_exact',
'remaindernear':'remainder_near',
'divideint':'divide_int',
'squareroot':'sqrt',
'apply':'_apply', 'apply':'_apply',
'class':'number_class', 'class':'number_class',
'comparesig':'compare_signal', 'comparesig':'compare_signal',
'comparetotal':'compare_total', 'comparetotal':'compare_total',
'comparetotmag':'compare_total_mag', 'comparetotmag':'compare_total_mag',
'copyabs':'copy_abs',
'copy':'copy_decimal', 'copy':'copy_decimal',
'copyabs':'copy_abs',
'copynegate':'copy_negate', 'copynegate':'copy_negate',
'copysign':'copy_sign', 'copysign':'copy_sign',
'and':'logical_and', 'divideint':'divide_int',
'or':'logical_or',
'xor':'logical_xor',
'invert':'logical_invert', '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', 'maxmag':'max_mag',
'minmag':'min_mag', 'minmag':'min_mag',
'nextminus':'next_minus', 'nextminus':'next_minus',
'nextplus':'next_plus', 'nextplus':'next_plus',
'nexttoward':'next_toward', 'nexttoward':'next_toward',
'or':'logical_or',
'reduce':'normalize', '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 # For some operations (currently exp, ln, log10, power), the decNumber
# reference implementation imposes additional restrictions on the # reference implementation imposes additional restrictions on the
# context and operands. These restrictions are not part of the # context and operands. These restrictions are not part of the
...@@ -321,7 +347,7 @@ class DecimalTest(unittest.TestCase): ...@@ -321,7 +347,7 @@ class DecimalTest(unittest.TestCase):
print "--", self.context print "--", self.context
try: try:
result = str(funct(*vals)) result = str(funct(*vals))
if fname == 'same_quantum': if fname in LOGICAL_FUNCTIONS:
result = str(int(eval(result))) # 'True', 'False' -> '1', '0' result = str(int(eval(result))) # 'True', 'False' -> '1', '0'
except Signals, error: except Signals, error:
self.fail("Raised %s in %s" % (error, s)) self.fail("Raised %s in %s" % (error, s))
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment