Re: factorial of negative numbers

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Peter Eisentraut <peter(dot)eisentraut(at)2ndquadrant(dot)com>
Cc: pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: factorial of negative numbers
Date: 2020-06-15 13:59:21
Message-ID: 1121379.1592229561@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Peter Eisentraut <peter(dot)eisentraut(at)2ndquadrant(dot)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

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Bruce Momjian 2020-06-15 14:10:32 Re: create database with template doesn't copy database ACL
Previous Message Masahiko Sawada 2020-06-15 13:35:49 Re: Transactions involving multiple postgres foreign servers, take 2