How to do exponentiation in clojure?

前端 未结 13 1805
执笔经年
执笔经年 2021-01-30 12:32

How can I do exponentiation in clojure? For now I\'m only needing integer exponentiation, but the question goes for fractions too.

13条回答
  •  迷失自我
    2021-01-30 12:58

    Use clojure.math.numeric-tower, formerly clojure.contrib.math.


    API Documentation


    (ns user
      (:require [clojure.math.numeric-tower :as m]))
    
    (defn- sqr
      "Uses the numeric tower expt to square a number"
      [x]
      (m/expt x 2))
    

提交回复
热议问题