Skip to content

Commit 8b84957

Browse files
committed
Change = to include type of boxed numbers (and collections thereof). Use == for inter-type numeric equivalence.
1 parent 863decc commit 8b84957

File tree

2 files changed

+14
-12
lines changed

2 files changed

+14
-12
lines changed

src/clj/clojure/core.clj

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -698,7 +698,7 @@
698698
([x y] (clojure.lang.Util/identical x y)))
699699

700700
;equiv-based
701-
(defn =
701+
#_(defn =
702702
"Equality. Returns true if x equals y, false if not. Same as
703703
Java x.equals(y) except it also works for nil, and compares
704704
numbers and collections in a type-independent manner. Clojure's immutable data
@@ -717,12 +717,11 @@
717717
false)))
718718

719719
;equals-based
720-
#_(defn =
721-
"Equality. Returns true if x equals y, false if not. Same as
722-
Java x.equals(y) except it also works for nil, and compares
723-
numbers and collections in a type-independent manner. Clojure's immutable data
724-
structures define equals() (and thus =) as a value, not an identity,
725-
comparison."
720+
(defn =
721+
"Equality. Returns true if x equals y, false if not. Same as Java
722+
x.equals(y) except it also works for nil. Boxed numbers must have
723+
same type. Clojure's immutable data structures define equals() (and
724+
thus =) as a value, not an identity, comparison."
726725
{:inline (fn [x y] `(. clojure.lang.Util equals ~x ~y))
727726
:inline-arities #{2}
728727
:added "1.0"}
@@ -953,7 +952,8 @@
953952
false)))
954953

955954
(defn ==
956-
"Returns non-nil if nums all have the same value, otherwise false"
955+
"Returns non-nil if nums all have the equivalent
956+
value (type-independent), otherwise false"
957957
{:inline (fn [x y] `(. clojure.lang.Numbers (equiv ~x ~y)))
958958
:inline-arities #{2}
959959
:added "1.0"}

src/jvm/clojure/lang/Util.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ static public boolean equals(Object k1, Object k2){
3535
return k1 != null && k1.equals(k2);
3636
}
3737

38+
//*
3839
static public boolean equals(long x, long y){
3940
return x == y;
4041
}
@@ -44,20 +45,21 @@ static public boolean equals(double x, double y){
4445
}
4546

4647
static public boolean equals(long x, Object y){
47-
return equals((Object)x,y);
48+
return equals(Numbers.num(x),y);
4849
}
4950

5051
static public boolean equals(Object x, long y){
51-
return equals(x,(Object)y);
52+
return equals(x,Numbers.num(y));
5253
}
5354

5455
static public boolean equals(double x, Object y){
55-
return equals((Object)x,y);
56+
return equals((Double)x,y);
5657
}
5758

5859
static public boolean equals(Object x, double y){
59-
return equals(x,(Object)y);
60+
return equals(x,(Double)y);
6061
}
62+
//*/
6163

6264
static public boolean identical(Object k1, Object k2){
6365
return k1 == k2;

0 commit comments

Comments
 (0)