davedelong / DDMathParser

String → Number
MIT License
854 stars 153 forks source link

Factorial answer incorrect starting 21! #185

Closed m4mario closed 2 months ago

m4mario commented 2 months ago

Up till 20! factorial, the answer is correct. But starting 21!, the answers are incorrect by (-1)!. For example, if I calculate 22!, the answer I get is (22-1)!, or 21!

And the answer for 20! and 21! factorial is the same.

m4mario commented 2 months ago

In function func factorial() -> Double

This line is the problem

for i in 2 ..< Int(self)

Changing it to this fixes the issue.

for i in 2 ..< Int(self+1.0)

davedelong commented 2 months ago

At first I thought this was a different issue, but you have indeed found a legit bug! Thank you!