Back

round (clj)

(source)

function

(round a)
Returns the closest long to a. If equally close to two values, return the one closer to ##Inf. If a is ##NaN => 0 If a is ##-Inf or < Long/MIN_VALUE => Long/MIN_VALUE If a is ##Inf or > Long/MAX_VALUE => Long/MAX_VALUE See: https://docs.oracle.com/javase/8/docs/api/java/lang/Math.html#round-double-

Examples

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

(deftest test-radians-degrees-roundtrip
  (doseq [d (range 0.0 360.0 5.0)]
    (is (ulp= (m/round d) (m/round (-> d m/to-radians m/to-degrees)) 1))))

(deftest test-round
  (is (= 0 (m/round ##NaN)))
  (is (= Long/MIN_VALUE (m/round ##-Inf)))
  (is (= Long/MIN_VALUE (m/round (- Long/MIN_VALUE 2.0))))
  (is (= Long/MAX_VALUE (m/round ##Inf)))
  (is (= Long/MAX_VALUE (m/round (+ Long/MAX_VALUE 2.0))))
  (is (= 4 (m/round 3.5))))