Back

exp (clj)

(source)

function

(exp a)
Returns Euler's number e raised to the power of a. If a is ##NaN => ##NaN If a is ##Inf => ##Inf If a is ##-Inf => +0.0 See: https://docs.oracle.com/javase/8/docs/api/java/lang/Math.html#exp-double-

Examples

clojure
(ns clojure.test-clojure.math
  (:require
    [clojure.test :refer :all]
    [clojure.math :as m]))

(deftest test-exp
  (is (NaN? (m/exp ##NaN)))
  (is (= ##Inf (m/exp ##Inf)))
  (is (pos-zero? (m/exp ##-Inf)))
  (is (ulp= (m/exp 0.0) 1.0 1))
  (is (ulp= (m/exp 1) m/E 1)))

(deftest test-expm1
  (is (NaN? (m/expm1 ##NaN)))
  (is (= ##Inf (m/expm1 ##Inf)))
  (is (= -1.0 (m/expm1 ##-Inf)))
  (is (= 0.0 (m/expm1 0.0))))

(deftest test-get-exponent
  (is (= (inc Double/MAX_EXPONENT) (m/get-exponent ##NaN)))
  (is (= (inc Double/MAX_EXPONENT) (m/get-exponent ##Inf)))
  (is (= (inc Double/MAX_EXPONENT) (m/get-exponent ##-Inf)))
  (is (= (dec Double/MIN_EXPONENT) (m/get-exponent 0.0)))
  (is (= 0 (m/get-exponent 1.0)))
  (is (= 13 (m/get-exponent 12345.678))))
migae/lab.clj.appengine
(ns migae.math
  (:require [clojure.math.numeric-tower :as math]
            [compojure.core :refer :all]
            [compojure.route :as route]
            [ring.util.response :as rsp]
            [ring.util.servlet :as ring]
            [ring.middleware.defaults :refer :all]))

(defroutes math-routes
  (context
   "/math" []
   (GET "/plus" {params :query-params}  ; query string params
        (let [x (read-string (get params "x"))
              y (read-string (get params "y"))]
          (str (+ x y) "\n")))
   (GET "/foo" []
         (str "bar"))
   (POST "/minus" [x y :as req]        ; body params
         (str (- (read-string x) (read-string y)) "\n"))
   (GET "/times/:x/:y" [x y]           ; named (path) params
        (-> (rsp/response (str (* (read-string x) (read-string y)) "\n"))
            (rsp/content-type "text/html")))
   (GET "/power" {:keys [headers] :as req} ; header params
        (let [x (read-string (get headers "x-x"))
              y (read-string (get headers "x-y"))]
          (str (math/expt x y) "\n")))
    (route/not-found "<h1>Math API not found</h1>")))
wedesoft/sfsim25
(require '[clojure.math :refer (sin cos PI sqrt exp log pow)]
         '[fastmath.vector :refer (vec3)]
         '[fastmath.matrix :refer (mulm)]
         '[sfsim25.render :refer :all]
         '[sfsim25.matrix :refer :all]
         '[sfsim25.worley :refer :all]
         '[sfsim25.shaders :as shaders]
         '[sfsim25.clouds :refer :all]
         '[sfsim25.util :refer :all])

(def alpha (atom 0))
(def beta (atom 0))
(def threshold (atom 0.4))
(def multiplier (atom 4.0))
(def curl-scale-exp (atom (log 4)))
(def cloud-scale-exp (atom (log 2)))
(def prevailing (atom 0.1))
(def whirl (atom 1.0))

(def t0 (atom (System/currentTimeMillis)))
(while (not (GLFW/glfwWindowShouldClose window))
       (let [t1 (System/currentTimeMillis)
             dt (- t1 @t0)
             ra (if (@keystates GLFW/GLFW_KEY_KP_2) 0.001 (if (@keystates GLFW/GLFW_KEY_KP_8) -0.001 0))
             rb (if (@keystates GLFW/GLFW_KEY_KP_4) 0.001 (if (@keystates GLFW/GLFW_KEY_KP_6) -0.001 0))
             tr (if (@keystates GLFW/GLFW_KEY_Q) 0.001 (if (@keystates GLFW/GLFW_KEY_A) -0.001 0))
             ta (if (@keystates GLFW/GLFW_KEY_W) 0.001 (if (@keystates GLFW/GLFW_KEY_S) -0.001 0))
             cs (if (@keystates GLFW/GLFW_KEY_E) 0.001 (if (@keystates GLFW/GLFW_KEY_D) -0.001 0))
             os (if (@keystates GLFW/GLFW_KEY_R) 0.001 (if (@keystates GLFW/GLFW_KEY_F) -0.001 0))
             pw (if (@keystates GLFW/GLFW_KEY_T) 0.001 (if (@keystates GLFW/GLFW_KEY_G) -0.001 0))
             ps (if (@keystates GLFW/GLFW_KEY_Y) 0.001 (if (@keystates GLFW/GLFW_KEY_H) -0.001 0))]
         (swap! alpha + (* dt ra))
         (swap! beta + (* dt rb))
         (swap! threshold + (* dt tr))
         (swap! multiplier + (* dt ta))
         (swap! whirl + (* dt pw))
         (swap! prevailing + (* dt ps))
         (swap! curl-scale-exp + (* dt cs))
         (swap! cloud-scale-exp + (* dt os))
         (when (or (nil? @cloud-cover-tex) (not (zero? pw)) (not (zero? ps)) (not (zero? cs)) (not (zero? os)))
           (when-not (nil? @cloud-cover-tex)
                     (destroy-texture @cloud-cover-tex))
           (reset! cloud-cover-tex
             (cloud-cover-cubemap :size 512
                                  :worley-size worley-size
                                  :worley-south worley-south
                                  :worley-north worley-north
                                  :worley-cover worley-cover
                                  :flow-octaves [0.5 0.25 0.125]
                                  :cloud-octaves [0.25 0.25 0.125 0.125 0.0625 0.0625]
                                  :whirl @whirl
                                  :prevailing @prevailing
                                  :curl-scale (exp @curl-scale-exp)
                                  :cover-scale (exp @cloud-scale-exp)
                                  :num-iterations 50
                                  :flow-scale (* 1.5e-3 (exp @curl-scale-exp)))))
         (let [mat (mulm (rotation-y @beta) (rotation-x @alpha))]
           (onscreen-render window
                            (clear (vec3 0 0 0))
                            (use-program program)
                            (uniform-sampler program "cubemap" 0)
                            (uniform-matrix3 program "rotation" mat)
                            (uniform-float program "threshold" @threshold)
                            (uniform-float program "multiplier" @multiplier)
                            (use-textures {0 @cloud-cover-tex})
                            (render-quads vao)))
         (GLFW/glfwPollEvents)
         (print (format "\rthreshold = %.3f, multiplier = %.3f, curlscale = %.3f, cloudscale = %.3f, whirl = %.3f, prevailing = %.3f"
                        @threshold @multiplier (exp @curl-scale-exp) (exp @cloud-scale-exp) @whirl @prevailing))
         (flush)
         (swap! t0 + dt)))