Back
signum (clj)
(source)function
(signum d)
Returns the signum function of d - zero for zero, 1.0 if >0, -1.0 if <0.
If d is ##NaN => ##NaN
See: https://docs.oracle.com/javase/8/docs/api/java/lang/Math.html#signum-double-
Examples
clojure
(ns clojure.test-clojure.math
(:require
[clojure.test :refer :all]
[clojure.math :as m]))
(deftest test-signum
(is (NaN? (m/signum ##NaN)))
(is (zero? (m/signum 0.0)))
(is (zero? (m/signum -0.0)))
(is (= 1.0 (m/signum 42.0)))
(is (= -1.0 (m/signum -42.0))))
clojang/jiface
(ns ^:unit
jiface.test.erlang.types-test
(:require
[clojure.math.numeric-tower :as math]
[clojure.test :refer :all]
[jiface.erlang :as erlang]
[jiface.erlang.types :as types]
[jiface.erlang.atom :as atom-type]
[jiface.erlang.atom :as boolean-type]
[jiface.erlang.map :as map-type]
[jiface.erlang.tuple :as tuple-type]
[jiface.erlang.list :as list-type]
[jiface.erlang.int :as char-type]
[jiface.erlang.int :as long-type]
[jiface.erlang.string :as string-type])
(:import
(com.ericsson.otp.erlang OtpErlangAtom
OtpErlangBoolean
OtpErlangChar)
(java.lang Long)
(java.math BigInteger)))
(deftest long-protocol-test
(let [long-1 (types/long (* -1 java.lang.Long/MAX_VALUE))
long-2 (types/long java.lang.Long/MAX_VALUE)
same-long (types/long java.lang.Long/MAX_VALUE)
int-long (types/long (new Long java.lang.Integer/MAX_VALUE))
short-long (types/long (new Long java.lang.Short/MAX_VALUE))]
(is (= "-9223372036854775807" (long-type/->str long-1)))
(is (= "9223372036854775807" (long-type/->str long-2)))
(is (= true (long-type/equal? long-2 same-long)))
(is (= false (long-type/equal? long-1 same-long)))
(is (= -2147483616 (long-type/hash long-1)))
(is (= 2147483616 (long-type/hash long-2)))
(is (= 9223372036854775807 (long-type/get-bigint-value long-2)))
(is (= 63 (long-type/get-bit-length long-2)))
(is (= \a (long-type/get-char-value (types/long 97))))
(is (= 2147483647 (long-type/get-int-value int-long)))
(is (= true (long-type/long? long-2)))
(is (= false (long-type/ulong? long-1)))
(is (= true (long-type/ulong? long-2)))
(is (= 9223372036854775807 (long-type/get-long-value long-2)))
(is (= 32767 (long-type/get-short-value short-long)))
(is (= 1 (long-type/get-signum long-2)))
(is (= 2147483647 (long-type/get-uint-value int-long)))
(is (= 32767 (long-type/get-ushort-value short-long)))))