[prev in list] [next in list] [prev in thread] [next in thread] 

List:       python-ideas
Subject:    [Python-ideas] A better math.factorial
From:       "Jonatan " <pybots.il () gmail ! com>
Date:       2021-09-16 18:33:58
Message-ID: 163181723859.1302.4421424894371205668 () mail ! python ! org
[Download RAW message or body]

Currently, math.factorial only supports integers and not floats, whereas the \
"mathematical" version supports both integers and floats. I.e:
```
import math


def better_factorial(n):
    return n * math.gamma(n)

print(math.factorial(10) == better_factorial(10))
```

This ends up in `True`, as that's correct.
However, `math.factorial(math.pi)` (for example, or any float)
Ends up in `ValueError: factorial() only accepts integral values`.
unlike `better_factorial(math.pi)` which would end up in 7.188082728976031.

My proposal is to make another function for floats, or even use the same \
math.factorial function and check inside it whether the given input is an integer or \
a float object.

I would like to hear your review.
Jonathan.
_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-leave@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at https://mail.python.org/archives/list/python-ideas@python.org/message/HID2JPHO56Y2ZZ3MJGEGRDGPMJJLF5T3/
 Code of Conduct: http://python.org/psf/codeofconduct/


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic