Post Reply 
%NFACT bug
01-08-2014, 03:01 AM
Post: #1
%NFACT bug
It appears to me that the System RPL entry %NFACT on my 50g doesn't work properly. This computes the factorial of a real number. Note that it's different from %FACT which computes gamma(x+1) and works correctly.

%NFACT appears to return IP(ABS(x))! There are 2 bugs
  1. It doesn't honor system flag 22 when the result overflows. It returns 9.99999999999E499, even if the flag is clear
  2. If x is between -1 and 1 (exclusive of the endpoints), it return 9.99999999999E499 instead of 1.


Hoping that someone can confirm or explain to me why I'm wrong.

Thanks,
Dave
Find all posts by this user
Quote this message in a reply
01-08-2014, 03:14 AM
Post: #2
RE: %NFACT bug
(01-08-2014 03:01 AM)David Hayden Wrote:  It appears to me that the System RPL entry %NFACT on my 50g doesn't work properly. This computes the factorial of a real number. Note that it's different from %FACT which computes gamma(x+1) and works correctly.

%NFACT appears to return IP(ABS(x))! There are 2 bugs
  1. It doesn't honor system flag 22 when the result overflows. It returns 9.99999999999E499, even if the flag is clear
  2. If x is between -1 and 1 (exclusive of the endpoints), it return 9.99999999999E499 instead of 1.


Hoping that someone can confirm or explain to me why I'm wrong.

Thanks,
Dave

Sounds like this bug I reported a while back: http://bugs.hpcalc.org/show_bug.cgi?id=255

This bug affects pretty much ANY command that uses argument checking and auto-converts DOZINT types to DOREAL -- which is to say a lot of commands are affected by it. I found the bug while porting Jazz for the HP48 series to the HP50G.

Graph 3D | QPI | SolveSys
Find all posts by this user
Quote this message in a reply
01-08-2014, 01:32 PM
Post: #3
RE: %NFACT bug
(01-08-2014 03:14 AM)Han Wrote:  Sounds like this bug I reported a while back: http://bugs.hpcalc.org/show_bug.cgi?id=255
I don't think so. %NFACT is a primitive code object and operates on real numbers only. It doesn't call CK&DISPATCH1
Find all posts by this user
Quote this message in a reply
01-08-2014, 06:12 PM
Post: #4
RE: %NFACT bug
If I am not mistaken, is flag 22 is for cases when you truly have infinity (such as division by 0), whereas flag 21 is for overflow. %NFACT does respect flag 21.

As for the second issue, it has to do with the fact at %NFACT (and pretty much any other SysRPL command) does not do any argument checking. That it works for almost any decimal value is a mere bonus due to the algorithm implemented. Basically the algorithm checks a few special cases and then proceeds with the general algorithm, which fails for the case when the input \( x \) satisfies \( x\in (-1,1) \). Perhaps you are expecting it to return the factorial of any real number, whereas the program is designed to return the factorial of an DOREAL integer.

Graph 3D | QPI | SolveSys
Find all posts by this user
Quote this message in a reply
01-09-2014, 03:02 AM
Post: #5
RE: %NFACT bug
(01-08-2014 06:12 PM)Han Wrote:  If I am not mistaken, is flag 22 is for cases when you truly have infinity (such as division by 0), whereas flag 21 is for overflow. %NFACT does respect flag 21.

Ah! That's it. Thanks so much.

(01-08-2014 06:12 PM)Han Wrote:  Perhaps you are expecting it to return the factorial of any real number, whereas the program is designed to return the factorial of an DOREAL integer.
Yes I think that's fair. A good way to look at it is that %NFACT expects a DOREAL integer argument greater than zero. The fact that it returns something sort-of meaningful for DOREAL integers less than -1 is just coincidence.

Thanks for your help!
Dave
Find all posts by this user
Quote this message in a reply
Post Reply 




User(s) browsing this thread: 1 Guest(s)