Skip to content

Instantly share code, notes, and snippets.

Created July 25, 2016 14:32
Show Gist options
  • Save anonymous/ceb5efda41a52d69e7294a4b49e28871 to your computer and use it in GitHub Desktop.
Save anonymous/ceb5efda41a52d69e7294a4b49e28871 to your computer and use it in GitHub Desktop.
VALUE factorials_num_double_factorial(VALUE num)
{
long value = NUM2INT(num), result = 1;
if(value % 2 == 0) {
return INT2NUM(
pow(2, value / 2) * NUM2INT(
factorials_num_factorial(INT2NUM(value / 2))
)
);
} else {
return INT2NUM(
NUM2INT(factorials_num_factorial(num)) / (
pow(2, (value - 1) / 2) * NUM2INT(
factorials_num_factorial(INT2NUM((value - 1) / 2))
)
)
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment