Re: Bug in HP 20b: nCr with noninteger r Message #7 Posted by Chuck on 31 Mar 2009, 4:43 p.m., in response to message #1 by Thomas Klemm
My guess is that the factorial function actually utilizes the gamma function, and nCr has an algorithm that does not utilize gamma.
<Michael got there first>
While working on this, I decided to try it out on the HP42S. Of course the nCr button with nonintegers doesn't work. The factorial function also doesn't work because there is a built in gamma function. Here's a little program I wrote for the HP42S to do it...
01 LBL "NCR"
02 STO 01
03 Rolldown
04 STO 02
05 1
06 +
07 GAMMA
08 1
09 RCL+ 01
10 GAMMA
11 / "divide"
12 RCL 02
13 RCL 01
14 1
15 +
16 GAMMA
17 /
18 RTN
Put two numbers on the stack and execute NCR
It's most likely not the shortest such program, but works like a charm on your noninteger problem. But, now the REALLY STRANGE PART....
...in doing a problem like 5 nCr 5 or 5 nCr 0 on the 42S I get for an output
Out of Range
x: 1.0000
However, stepping through the program to trouble shoot it, there is no "Out of Range" warning. And, executing the SAME program using Free42 on my ipod I get no "Out of Range Error". Can someone explain that to me?
CHUCK
Edited: 31 Mar 2009, 4:46 p.m.
