Back

rint (clj)

(source)

function

(rint a)
Returns the double closest to a and equal to a mathematical integer. If two values are equally close, return the even one. If a is ##NaN or ##Inf or ##-Inf or zero => a See: https://docs.oracle.com/javase/8/docs/api/java/lang/Math.html#rint-double-

Examples

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

(deftest test-rint
  (is (NaN? (m/rint ##NaN)))
  (is (= ##Inf (m/rint ##Inf)))
  (is (= ##-Inf (m/rint ##-Inf)))
  (is (= 1.0 (m/rint 1.2)))
  (is (neg-zero? (m/rint -0.01))))
arohner/spectrum
(ns spectrum.repl
  (:require [clojure.math.combinatorics :as combo]
            [clojure.spec.alpha :as s]
            [clojure.spec.test.alpha :as stest]
            [clojure.tools.analyzer.jvm :as ana.jvm]
            [clojure.test.check.generators :as gen]
            [spectrum.compiler :as c]
            [spectrum.compiler-test :as ct]
            [spectrum.data :as data]
            [spectrum.equations :as eq]

;; (defmacro inspect [expr]
;;   `(do
;;      (let [in# (quote ~expr)
;;          resp# (do ~expr)]
;;        (printf "%s is %s\n" in# (with-out-str (print resp#)))
;;        resp#)))
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 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)))