Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

factorial(n) function #3253

Merged
merged 5 commits into from
Jan 30, 2025
Merged

factorial(n) function #3253

merged 5 commits into from
Jan 30, 2025

Conversation

Astralcircle
Copy link
Contributor

@Astralcircle Astralcircle commented Jan 29, 2025

Adds a simple E2 function to calculate the factorial of a number.

@Alexandre425
Copy link
Contributor

Wouldn't it be more efficient to check whether n is greater than 171, returning +inf immediately?

@Astralcircle
Copy link
Contributor Author

math.min protects against NaN

@CornerPin
Copy link
Contributor

CornerPin commented Jan 29, 2025

I think it would be better to precompute the results instead and store them in a lookup table for $O(1)$ time, otherwise the cost should be made proportional to n. Should probably return NaN for $n \lt 0$ as well.

Co-authored-by: thegrb93 <[email protected]>
@thegrb93 thegrb93 merged commit c75ee43 into wiremod:master Jan 30, 2025
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants