If you really need a function, not a method, you can simply wrap it:
(defn pow [be] (Math/pow be))
And in this function you can apply it to int or the like. Functions are often more useful in that methods, because you can pass them as parameters to other functions - in this case map comes to my mind.
If you really need to avoid interacting with Java, you can write your own nutrition function. For example, this is a simple function:
(defn pow [np] (let [result (apply * (take (abs p) (cycle [n])))] (if (neg? p) (/ 1 result) result)))
This calculates the power for an integer exponent (i.e. no roots).
Also, if you are dealing with large numbers, you can use BigInteger instead of int .
And if you are dealing with very large numbers, you can express them as lists of numbers and write your own arithmetic functions for streaming through them, since they calculate the result and output the result to some other stream.
Goran Jovic Feb 20 '11 at 2:00 p.m. 2011-02-20 14:00
source share