Skip to content

Instantly share code, notes, and snippets.

@nobuh
Created August 8, 2011 01:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nobuh/1131012 to your computer and use it in GitHub Desktop.
Save nobuh/1131012 to your computer and use it in GitHub Desktop.
Test recursive factorial on rhino
// 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