fork(1) download
  1. ; three powering algorithms
  2.  
  3. (define (pow-linear b e)
  4. (if (zero? e) 1
  5. (* b (pow-linear b (- e 1)))))
  6.  
  7. (display (pow-linear 2 16)) (newline)
  8.  
  9. (define (pow-logarithmic b e)
  10. (cond ((zero? e) 1)
  11. ((even? e) (pow-logarithmic (* b b) (/ e 2)))
  12. (else (* b (pow-logarithmic (* b b) (/ (- e 1) 2))))))
  13.  
  14. (display (pow-logarithmic 2 16)) (newline)
  15.  
  16. (define (pow-constant b e)
  17. (exp (* (log b) e)))
  18.  
  19. (display (pow-constant 2 16)) (newline)
Success #stdin #stdout 0s 7272KB
stdin
Standard input is empty
stdout
65536
65536
65536.0