sharkdp / insect

High precision scientific calculator with support for physical units
https://numbat.dev/
MIT License
3.18k stars 126 forks source link

Output error when input to factorial is not a non-negative integer #387

Closed ghost closed 1 year ago

ghost commented 1 year ago

The standard definition of factorial only deals with non-negative integers. If you decided to implement only it then you should give errors when the users tried to calculate factorial of real numbers. The current behavior is you rounded the real number to the nearest integer and returned the factorial of this integer instead. For example, pi! will be calculated as 4!, e! will be calculated as 3!. This is wrong. Either implement the extended definition of factorial for real numbers using Gamma function or simply spit out an error if the input is not a non-negative integer.

sharkdp commented 1 year ago

Either implement the extended definition of factorial for real numbers using Gamma function

we have that already: gamma(…).

or simply spit out an error if the input is not a non-negative integer.

That's probably a good idea, yes.

sharkdp commented 1 year ago

This is now fixed in Numbat. You can try it online here: https://numbat.dev/?q=%28-3%29%21