[S] Don't assume factorial() gives you integer values

Steven P. Millard (steven.p.millard@mci2000.com)
Mon, 30 Nov 1998 08:50:10 -0800


Hello Everyone,

Here is one that bit me recently. The factorial() function calls the
gamma() function, so for example you can compute factorial(2.7). Now
watch:

> factorial(8)
[1] 40320

> length(numeric(factorial(8)))
[1] 40319

I consider this a bug. I assume this has to do with machine
representation, but it would be nice if the factorial function gave you
a result in integer mode if you supply it with an argument that is an
integer.

When I say "an argument that is an integer", however, I have to be
careful since you get the following:

> is.integer(8)
[1] F

so I guess I'm proposing that if the argument to factorial() is
explicitly set to integer mode, then the result should be an integer.
That is, I'd like to see the following behavior:

> length(numeric(factorial(as.integer(8))))
[1] 40320

Sincerely,

--Steve M.

_____________
| *** | Steven P. Millard, Ph.D.
| * |
| * * * | P robability, TEL: 206-528-4877
| * * * | S tatistics & FAX: 206-528-4802
| * | I nformation E-mail: SMillard@ProbStatInfo.com
| * | Web: www.ProbStatInfo.com
| *** | 7723 44th Avenue NE
|___________| Seattle, WA 98115-5117 USA

-----------------------------------------------------------------------
This message was distributed by s-news@wubios.wustl.edu. To unsubscribe
send e-mail to s-news-request@wubios.wustl.edu with the BODY of the
message: unsubscribe s-news