mardi 18 avril 2017

factorial function with custom numbers doesn't work

recently I've been working on a library to handle very large numbers with thousands of digits. I have now worked on a factorial function for these things as I just set up multiplication.

largeNum factorial(largeNum& input) {
    if (input > one) return (input * factorial(--input));
    else return one;
}

"one" is a largeNum defined to have a value of"one" with a "+" sign since I haven't yet implemented integer conversion.

Factorial is a friend function of the largeNum class. I do not get any syntax errors, it has to be logical.

The prefix -- operator is properly overloaded and also tested.

So are multiplication and the ">" operator.

  • Entering 5 returns 24 which is 4!
  • Entering 6 returns 120 which is 5!. And so on.

Maybe I'm just being plain blind as I'm a little sleep deprived but I need some help here. Cheers.






Comments
0 Comments

0 commentaires:

Enregistrer un commentaire