Re: factorial of negative numbers
Tom Lane <tgl@sss.pgh.pa.us>
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Peter Eisentraut <peter.eisentraut@2ndquadrant.com>
Cc: pgsql-hackers <pgsql-hackers@postgresql.org>
Date: 2020-06-15T13:59:21Z
Lists: pgsql-hackers
Peter Eisentraut <peter.eisentraut@2ndquadrant.com> writes: > Adjacent to the discussion in [0] I wanted to document the factorial() > function and expand the tests for that slightly with some edge cases. > ... > I propose to change this to error out for negative numbers. +1 for all of this, with a couple trivial nitpicks about the error changes: * I'd have written the error as "factorial of a negative number is undefined" ... not sure what a grammar stickler would say about it, but that seems more natural to me. * I'd leave the "if (num <= 1)" test after the error check as-is; it's probably a shade cheaper than "if (num == 0 || num == 1)". regards, tom lane
Commits
-
Disallow factorial of negative numbers
- 0a40563eadc6 14.0 landed
-
Expand tests for factorial
- 9d402c73ade4 14.0 landed
-
doc: Document factorial function
- 4c5cf5431410 14.0 landed
-
Attached is a patch implementing factorial(), returning numeric. Points
- 04a4821adef3 8.0.0 cited