Back
sqrt (clj)
(source)function
(sqrt a)
Returns the positive square root of a.
If a is ##NaN or negative => ##NaN
If a is ##Inf => ##Inf
If a is zero => a
See: https://docs.oracle.com/javase/8/docs/api/java/lang/Math.html#sqrt-double-
Examples
clojure
(ns clojure.test-clojure.math
(:require
[clojure.test :refer :all]
[clojure.math :as m]))
(deftest test-sqrt
(is (NaN? (m/sqrt ##NaN)))
(is (NaN? (m/sqrt -1.0)))
(is (= ##Inf (m/sqrt ##Inf)))
(is (pos-zero? (m/sqrt 0)))
(is (= (m/sqrt 4.0) 2.0)))
Vaguery/klapaucius
(ns push.type.item.complex
(:require [push.instructions.dsl :as d]
[push.instructions.core :as i]
[clojure.math.numeric-tower :as nt :refer [sqrt]]
[push.type.core :as t]
[push.instructions.aspects :as aspects]
[push.type.definitions.complex :as complex]
))
(d/consume-top-of :complex :as :arg)
(d/calculate [:arg]
#(let [r (:re %1) i (:im %1)]
(nt/sqrt (+' (*' r r) (*' i i)))) :as :result)
(d/return-item :result)
))
Vaguery/klapaucius
(ns push.util.code-wrangling-test
(:require [push.util.stack-manipulation :as fix]
[push.util.numerics :as num]
[clojure.math.numeric-tower :as nt])
(:use midje.sweet)
(:use push.util.code-wrangling)
)
(fact "`safe-mod` handles NaN argument values by returning 0"
(safe-mod (nt/sqrt -2) 8) => 0
(safe-mod (nt/sqrt -2) 0) => 0
(safe-mod (nt/sqrt -2) (nt/sqrt -3)) => 0
(safe-mod 8 (nt/sqrt -3)) => 0
)
kshramt/sicp
(ns sicp.util
(:require
[clojure.core.typed
:refer [
IFn
Int
Num
ann
]
:as typed]
[clojure.pprint]
[clojure.math.numeric-tower
]
)
)
(typed/override-method clojure.lang.Numbers/remainder (IFn [Int Int -> Int]
[Num Num -> Num]))
(ann ^:no-check clojure.core/rem (IFn [Int Int -> Int]
[Num Num -> Num]))
(typed/override-method clojure.lang.Numbers/isNeg [Num -> Boolean])
(typed/override-method java.lang.Math/log [Num -> Double])
(ann ^:no-check clojure.math.numeric-tower/gcd [Int -> Int])
(ann ^:no-check clojure.math.numeric-tower/sqrt [Num -> Num])
wedesoft/sfsim25
(ns sfsim25.t-cubemap
(:require [midje.sweet :refer :all]
[malli.instrument :as mi]
[malli.dev.pretty :as pretty]
[sfsim25.conftest :refer (roughly-vector)]
[fastmath.vector :refer (vec3 add mult)]
[clojure.math :refer (sqrt PI)]
[sfsim25.util :as util]
[sfsim25.cubemap :refer :all :as cubemap])
(:import [fastmath.vector Vec3]))
(fact "Get normal vector for point on elevation map sloped in longitudinal direction"
(with-redefs [cubemap/surrounding-points (fn [& args] (for [j [-1 0 1] i [-1 0 1]] (vec3 (+ 6378000 i) j (- i))))]
(normal-for-point (vec3 1 0 0) 5 7 675 33 6378000.0) =>
(roughly-vector (vec3 (sqrt 0.5) 0 (sqrt 0.5)) 1e-6)))
(fact "Get normal vector for point on elevation map sloped in latitudinal direction"
(with-redefs [cubemap/surrounding-points (fn [& args] (for [j [-1 0 1] i [-1 0 1]] (vec3 (+ 6378000 j) j (- i))))]
(normal-for-point (vec3 1 0 0) 5 7 675 33 6378000.0) =>
(roughly-vector (vec3 (sqrt 0.5) (- (sqrt 0.5)) 0) 1e-6)))
wedesoft/sfsim25
(ns sfsim25.t-matrix
(:require [midje.sweet :refer :all]
[malli.instrument :as mi]
[malli.dev.pretty :as pretty]
[sfsim25.conftest :refer (roughly-matrix roughly-vector)]
[fastmath.matrix :as fm]
[fastmath.vector :as fv]
[clojure.math :refer (sqrt PI)]
[sfsim25.matrix :refer :all]
[sfsim25.quaternion :refer (->Quaternion rotation)]))
(def ca (/ (sqrt 3) 2))
(def sa 0.5)
(def -sa -0.5)