main: Decimal context sets the state of all traps.
This commit started because I noticed in the decimal documentation that BasicContext doesn't trap decimal.Subnormal, while oxrlib probably should. The point of this function is to set all the parts of a context that oxrlib should have to handle currency correctly and safely. With that motivation, it makes more sense to set all the traps exactly as we want them, rather than selectively setting "important" ones: they're all important.
This commit is contained in:
parent
cb17033279
commit
3b732505fa
1 changed files with 11 additions and 2 deletions
|
@ -7,8 +7,17 @@ import oxrlib.config
|
|||
def decimal_context(base=decimal.BasicContext):
|
||||
context = base.copy()
|
||||
context.rounding = decimal.ROUND_HALF_EVEN
|
||||
context.traps[decimal.Inexact] = False
|
||||
context.traps[decimal.Rounded] = False
|
||||
context.traps = {
|
||||
decimal.Clamped: True,
|
||||
decimal.DivisionByZero: True,
|
||||
decimal.FloatOperation: True,
|
||||
decimal.Inexact: False,
|
||||
decimal.InvalidOperation: True,
|
||||
decimal.Overflow: True,
|
||||
decimal.Rounded: False,
|
||||
decimal.Subnormal: True,
|
||||
decimal.Underflow: True,
|
||||
}
|
||||
return context
|
||||
|
||||
def main(arglist=None, stdout=sys.stdout, stderr=sys.stderr):
|
||||
|
|
Loading…
Reference in a new issue