Back

hypot (clj)

(source)

function

(hypot x y)
Returns sqrt(x^2 + y^2) without intermediate underflow or overflow. If x or y is ##Inf or ##-Inf => ##Inf If x or y is ##NaN and neither is ##Inf or ##-Inf => ##NaN See: https://docs.oracle.com/javase/8/docs/api/java/lang/Math.html#hypot-double-double-

Examples

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

(deftest test-hypot
  (is (= ##Inf (m/hypot 1.0 ##Inf)))
  (is (= ##Inf (m/hypot ##Inf 1.0)))
  (is (NaN? (m/hypot ##NaN 1.0)))
  (is (NaN? (m/hypot 1.0 ##NaN)))
  (is (= 13.0 (m/hypot 5.0 12.0))))
wedesoft/sfsim25
(ns sfsim25.t-interpolate
    (:require [midje.sweet :refer :all]
              [malli.instrument :as mi]
              [malli.dev.pretty :as pretty]
              [fastmath.vector :refer (vec3)]
              [clojure.math :refer (hypot)]
              [sfsim25.interpolate :refer :all]
              [sfsim25.util :refer (sqr)]))

(facts "Combine transformations to create non-linear space"
       (let [radius-space {:sfsim25.interpolate/forward #(vector (hypot %1 %2)) :sfsim25.interpolate/backward #(vector %1 0.0)}
             combined     (compose-space (linear-space [0.0] [1.0] [101]) radius-space)]
         (:sfsim25.interpolate/shape combined) => [101]
         ((:sfsim25.interpolate/forward combined) 3.0 4.0) => [500.0]
         ((:sfsim25.interpolate/backward combined) 500.0) => [5.0 0.0]))