File tree 2 files changed +10
-5
lines changed
2 files changed +10
-5
lines changed Original file line number Diff line number Diff line change @@ -286,8 +286,12 @@ extension Decimal : Hashable, Comparable {
286
286
return Int64 ( bitPattern: uint64Value)
287
287
}
288
288
289
- public var hashValue : Int {
290
- return Int ( bitPattern: __CFHashDouble ( doubleValue) )
289
+ public func hash( into hasher: inout Hasher ) {
290
+ // FIXME: This is a weak hash. We should rather normalize self to a
291
+ // canonical member of the exact same equivalence relation that
292
+ // NSDecimalCompare implements, then simply feed all components to the
293
+ // hasher.
294
+ hasher. combine ( doubleValue)
291
295
}
292
296
293
297
public static func == ( lhs: Decimal , rhs: Decimal ) -> Bool {
Original file line number Diff line number Diff line change @@ -363,9 +363,10 @@ class TestDecimal: XCTestCase {
363
363
XCTAssertFalse ( Decimal . nan. isTotallyOrdered ( belowOrEqualTo: Decimal ( 2.3 ) ) )
364
364
XCTAssertTrue ( Decimal ( 2 ) < Decimal ( 3 ) )
365
365
XCTAssertTrue ( Decimal ( 3 ) > Decimal ( 2 ) )
366
- #if !arch(arm)
367
- XCTAssertEqual ( 3275573729074 , Decimal ( 1234 ) . hashValue)
368
- #endif
366
+
367
+ // FIXME: This test is of questionable value. We should test hash properties.
368
+ XCTAssertEqual ( ( 1234 as Double ) . hashValue, Decimal ( 1234 ) . hashValue)
369
+
369
370
XCTAssertEqual ( Decimal ( - 9 ) , Decimal ( 1 ) - Decimal( 10 ) )
370
371
XCTAssertEqual ( Decimal ( 3 ) , Decimal ( 2 ) . nextUp)
371
372
XCTAssertEqual ( Decimal ( 2 ) , Decimal ( 3 ) . nextDown)
You can’t perform that action at this time.
0 commit comments