Created
August 8, 2011 01:07
-
-
Save nobuh/1131012 to your computer and use it in GitHub Desktop.
Test recursive factorial on rhino
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// mathcontext & bigdecimal.js is http://stz-ida.de/index.php?option=com_content&id=18 | |
load("mathcontext.js"); | |
load("bigdecimal.js"); | |
ONE = new BigDecimal("1"); | |
// Usage : factorial(new BigDecimal("number")) | |
function factorial (n) { | |
if (n.compareTo(ONE) == 0) { | |
return ONE; | |
} else { | |
return n.multiply(factorial (n.subtract(ONE))); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment