Python Forum
unexpected decimal.InvalidOperation - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: General (https://python-forum.io/forum-1.html)
+--- Forum: News and Discussions (https://python-forum.io/forum-31.html)
+--- Thread: unexpected decimal.InvalidOperation (/thread-35870.html)



unexpected decimal.InvalidOperation - Skaperen - Dec-25-2021

when doing decimal.Decimal('-inf')+decimal.Decimal('+inf') i got decimal.InvalidOperation raised. i was expecting to get Decimal('0'). there are a few operations on infinity that normal arithmetic allows such as inf-inf -> 0 and 0*inf -> 0 both of which the decimal.Decimal class does not allow. is there a reason for this or is it just up to whoever implemented decimal.Decimal?


RE: unexpected decimal.InvalidOperation - casevh - Dec-25-2021

The behavior you are seeing is part of IEEE-754 standard. The easiest chart I found is in the "Special Operations" section of https://steve.hollasch.net/cgindex/coding/ieeefloat.html.

The specification that defines the decimal library is available at:

http://speleotrove.com/decimal/decarith.html

The behavior is documented in section 7 Exceptional Conditions.


RE: unexpected decimal.InvalidOperation - Skaperen - Dec-25-2021

thanks for the info. i'll leave my opinions for another place and time.