Opened 12 years ago

Closed 12 years ago

#10374 closed defect (fixed)

dojox.math.factorial incorrectly returning NaN for non-integers

Reported by: Douglas Hays Owned by: Douglas Hays
Priority: high Milestone: 1.5
Component: Dojox Version: 1.4.0b
Keywords: Cc:
Blocked By: Blocking:


dojox.math.factorial(1.5) returns NaN but should return
sqrt(pi)*3/4 ~= 1.329340388179137 as defined by the gamma function.
You can also verify this with the Windows calc.exe program (scientific view has the n! button).

Attachments (1)

10374.patch (4.1 KB) - added by Douglas Hays 12 years ago.
reimplement factorial via gamma function

Download all attachments as: .zip

Change History (3)

comment:1 Changed 12 years ago by Eugene Lazutkin

Try not to overdo it: one can always complain that it doesn't work for negative and complex numbers, quaternions, and octonions too --- there are generalizations for these and other cases. ;-)

It reminds me of my robotics prof, who asked us to write a solver for a trivial quadratic polynomial, and embarrassed students by pointing out that their solution doesn't work for complex numbers, doesn't show that there are no solutions (a == 0, b == 0, c != 0), doesn't detect degenerated linear cases (a == 0, b != 0, or a != 0, b == 0), and in some cases any values are valid solutions (a == 0, b == 0, c == 0).

Changed 12 years ago by Douglas Hays

Attachment: 10374.patch added

reimplement factorial via gamma function

comment:2 Changed 12 years ago by Douglas Hays

Resolution: fixed
Status: newclosed

(In [20977]) Fixes #10374. Implement _gamma function so that fractional factorial can be calculated consistent with windows calc.exe program and TI calculators, but optimized for integers since this is the normal case. Add automated testcases.

Note: See TracTickets for help on using tickets.