-
Notifications
You must be signed in to change notification settings - Fork 37
Expand file tree
/
Copy pathfloat.cljc
More file actions
67 lines (64 loc) · 2.47 KB
/
float.cljc
File metadata and controls
67 lines (64 loc) · 2.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
(ns clojure.core-test.float
(:require [clojure.test :as t :refer [are deftest is]]
[clojure.core-test.number-range :as r]
[clojure.core-test.portability #?(:cljs :refer-macros :default :refer) [when-var-exists] :as p]))
(when-var-exists float
(deftest test-float
(are [expected x] (= expected (float x))
(float 1.0) 1
(float 0.0) 0
(float -1.0) -1
(float 1.0) 1N
(float 0.0) 0N
(float -1.0) -1N
;; The CLJS reader will read these values and convert to
;; double. Since they are all clean conversions, they match
(float 1.0) 12/12
(float 0.0) 0/12
(float -1.0) -12/12
(float 1.0) 1.0M
(float 0.0) 0.0M
(float -1.0) -1.0M
;; Since CLJS numbers are all doubles, casting r/min-double to a
;; float doesn't do anything, whereas in Clojure JVM it rounds
;; down to zero. All floating point numbers in Basilisp are doubles,
;; so float returns the same value here.
#?@(:cljs [r/min-double r/min-double]
:lpy [r/min-double r/min-double]
:phel [r/min-double r/min-double]
:default [(float 0.0) r/min-double]))
(is (NaN? (float ##NaN)))
#?@(:cljs
[(is (= r/max-double (float r/max-double)))
(is (= ##Inf (float ##Inf)))
(is (= ##-Inf (float ##-Inf)))
(is (= "0" (float "0")))
(is (= :0 (float :0)))]
:cljr
[(is (p/thrown? (float r/max-double)))
(is (p/thrown? (float ##Inf)))
(is (p/thrown? (float ##-Inf)))
(is (= (float 0.0) (float "0")))
(is (p/thrown? (float :0)))]
:lpy
[(is (= r/max-double (float r/max-double)))
(is (= ##Inf (float ##Inf)))
(is (= ##-Inf (float ##-Inf)))
(is (= 0.0 (float "0")))
(is (p/thrown? (float :0)))]
:default
[(is (p/thrown? (float r/max-double)))
(is (p/thrown? (float ##Inf)))
(is (p/thrown? (float ##-Inf)))
(is (p/thrown? (float "0")))
(is (p/thrown? (float :0)))])
#?@(:clj
[(is (instance? java.lang.Float (float 0)))
(is (instance? java.lang.Float (float 0.0)))
(is (instance? java.lang.Float (float 0N)))
(is (instance? java.lang.Float (float 0.0M)))]
:cljr
[(is (instance? System.Single (float 0)))
(is (instance? System.Single (float 0.0)))
(is (instance? System.Single (float 0N)))
(is (instance? System.Single (float 0.0M)))])))