Hi Jeff,

The decimal module docstring starts with:

"""
This is an implementation of decimal floating point arithmetic based on
the General Decimal Arithmetic Specification:

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

and IEEE standard 854-1987:

    http://en.wikipedia.org/wiki/IEEE_854-1987

Decimal floating point has finite precision with arbitrarily large bounds.
"""

I suggest you to look into these standards.

Victor

On Thu, Sep 30, 2021 at 9:13 AM Jeff Allen <ja...@farowl.co.uk> wrote:
>
> Is an implementation of Python free to make up its own answers to division 
> and modulus operatons in the case of inf and nan arguments?
>
> The standard library documentation says only that // is "rounded towards 
> minus infinity". The language reference says that :
>
> x == (x//y)*y + (x%y),
> the modulus has the same sign as y, and
> division by (either kind of) zero raises ZeroDivisionError .
>
> It's consistent, but it doesn't define the operator over the full range of 
> potential arguments. In Python 3.8 and 3.9:
>
> >>> from decimal import Decimal
> >>> Decimal('-3.14') // Decimal('Infinity')
> Decimal('-0')
> >>> -3.14 // float("inf")
> -1.0
> >>> import math
> >>> math.floor(-3.14 /  float("inf"))
> 0
>
> I can see sense in all three answers, as possible interpretations of "rounded 
> towards minus infinity", but I quite like decimal's. There seem to be no 
> regression tests for floor division of floats, and for modulus only with 
> finite arguments, perhaps intentionally.
>
> --
>
> Jeff Allen
>
> _______________________________________________
> Python-Dev mailing list -- python-dev@python.org
> To unsubscribe send an email to python-dev-le...@python.org
> https://mail.python.org/mailman3/lists/python-dev.python.org/
> Message archived at 
> https://mail.python.org/archives/list/python-dev@python.org/message/BXYBSUMNSP6AAAS6OL23ANSML4IOARVB/
> Code of Conduct: http://python.org/psf/codeofconduct/



-- 
Night gathers, and now my watch begins. It shall not end until my death.
_______________________________________________
Python-Dev mailing list -- python-dev@python.org
To unsubscribe send an email to python-dev-le...@python.org
https://mail.python.org/mailman3/lists/python-dev.python.org/
Message archived at 
https://mail.python.org/archives/list/python-dev@python.org/message/GLFGZ6D2YTFL3HYO4JL4OR6UAANR7JP6/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to