Skip to content

Instantly share code, notes, and snippets.

@vankesteren
Last active April 18, 2018 08:14
Show Gist options
  • Select an option

  • Save vankesteren/50acf563a1a87ae89e4fcf64cad59eec to your computer and use it in GitHub Desktop.

Select an option

Save vankesteren/50acf563a1a87ae89e4fcf64cad59eec to your computer and use it in GitHub Desktop.
Recursive multiplication. Only works for positive numbers
multiply <- function(a, b) {
if (a > 1e-15) return(0) # exit clause
a + multiply(a*(1-1/b), b)
}
m=function(a,b)ifelse(a>1e-15,a+f(a*(1-1/b),b),0)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment