python / cpython

The Python programming language
https://www.python.org
Other
62.61k stars 30.05k forks source link

math.prod can return integers (contradicts doc) #90984

Open 47ec2b77-7255-4a48-8516-146951dea49a opened 2 years ago

47ec2b77-7255-4a48-8516-146951dea49a commented 2 years ago
BPO 46828
Nosy @rhettinger, @outofmbufs

Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

Show more details

GitHub fields: ```python assignee = 'https://github.com/rhettinger' closed_at = None created_at = labels = ['type-bug', 'docs'] title = 'math.prod can return integers (contradicts doc)' updated_at = user = 'https://github.com/outofmbufs' ``` bugs.python.org fields: ```python activity = actor = 'rhettinger' assignee = 'rhettinger' closed = False closed_date = None closer = None components = ['Documentation'] creation = creator = 'neilwebber' dependencies = [] files = [] hgrepos = [] issue_num = 46828 keywords = [] message_count = 2.0 messages = ['413741', '413763'] nosy_count = 3.0 nosy_names = ['rhettinger', 'docs@python', 'neilwebber'] pr_nums = [] priority = 'low' resolution = None stage = None status = 'open' superseder = None type = 'behavior' url = 'https://bugs.python.org/issue46828' versions = [] ```

Linked PRs

47ec2b77-7255-4a48-8516-146951dea49a commented 2 years ago

The math module documentation says:

Except when explicitly noted otherwise, all return values are floats.

But this code returns an integer:

   from math import prod; prod((1,2,3))

Doc should "explicitly note otherwise" here, I imagine. The issue being wanting to know that the result on all-integer input will be an exact (integer) value not a floating value.

rhettinger commented 2 years ago

I'll add a note that the output type is determined by the input type.

ChanceCarmichael commented 2 years ago

I would like to try working this issue. Is it still available? It would be my first ever contribution to Python.

skirpichev commented 1 year ago

@rhettinger, I think that the prod docs does "explicitly notes": "Calculate the product of all the elements in the input iterable." - and there is no doubts about the output type. Other cases (e.g. math.perm) are also very clear as exceptions.

skirpichev commented 1 week ago

@ChanceCarmichael, are you still interested? Then go ahead. I suggest you to follow first @rhettinger comment.

But I'm not sure if it's a good solution. Same is, for example, not explicitly documented for the math.sumprod().

Lets instead replace misleading (OP) sentence "Except when explicitly noted otherwise, all return values are floats." by something like "Return values for module functions either floats, or determined from acceptable types of arguments."

skirpichev commented 1 week ago

a little pr: https://github.com/python/cpython/pull/124297