Index: src/OFConstantString.m ================================================================== --- src/OFConstantString.m +++ src/OFConstantString.m @@ -256,11 +256,11 @@ return [self mutableCopy]; } /* From protocol OFComparing */ -- (of_comparison_result_t)compare: (id)object +- (of_comparison_result_t)compare: (id )object { [self finishInitialization]; return [self compare: object]; } Index: src/OFDataArray.m ================================================================== --- src/OFDataArray.m +++ src/OFDataArray.m @@ -378,21 +378,21 @@ return NO; return YES; } -- (of_comparison_result_t)compare: (id)object +- (of_comparison_result_t)compare: (id )object { OFDataArray *otherDataArray; int comparison; size_t otherCount, minimumCount; if (![object isKindOfClass: [OFDataArray class]]) @throw [OFInvalidArgumentException exceptionWithClass: [self class] selector: _cmd]; - otherDataArray = object; + otherDataArray = (OFDataArray*)object; if ([otherDataArray itemSize] != itemSize) @throw [OFInvalidArgumentException exceptionWithClass: [self class] selector: _cmd]; Index: src/OFNumber.h ================================================================== --- src/OFNumber.h +++ src/OFNumber.h @@ -61,11 +61,12 @@ } of_number_type_t; /** * \brief Provides a way to store a number in an object. */ -@interface OFNumber: OFObject +@interface OFNumber: OFObject { union of_number_value { BOOL bool_; signed char char_; signed short short_; Index: src/OFNumber.m ================================================================== --- src/OFNumber.m +++ src/OFNumber.m @@ -935,10 +935,53 @@ if (type & OF_NUMBER_SIGNED || number->type & OF_NUMBER_SIGNED) return ([number intMaxValue] == [self intMaxValue]); return ([number uIntMaxValue] == [self uIntMaxValue]); } + +- (of_comparison_result_t)compare: (id)object +{ + OFNumber *number; + + if (![object isKindOfClass: [OFNumber class]]) + @throw [OFInvalidArgumentException + exceptionWithClass: [self class]]; + + number = object; + + if (type & OF_NUMBER_FLOAT || number->type & OF_NUMBER_FLOAT) { + double double1 = [self doubleValue]; + double double2 = [number doubleValue]; + + if (double1 > double2) + return OF_ORDERED_DESCENDING; + if (double1 < double2) + return OF_ORDERED_ASCENDING; + + return OF_ORDERED_SAME; + } else if (type & OF_NUMBER_SIGNED || number->type & OF_NUMBER_SIGNED) { + intmax_t int1 = [self intMaxValue]; + intmax_t int2 = [number intMaxValue]; + + if (int1 > int2) + return OF_ORDERED_DESCENDING; + if (int1 < int2) + return OF_ORDERED_ASCENDING; + + return OF_ORDERED_SAME; + } else { + uintmax_t uint1 = [self uIntMaxValue]; + uintmax_t uint2 = [number uIntMaxValue]; + + if (uint1 > uint2) + return OF_ORDERED_DESCENDING; + if (uint1 < uint2) + return OF_ORDERED_ASCENDING; + + return OF_ORDERED_SAME; + } +} - (uint32_t)hash { uint32_t hash; uint8_t i; Index: src/OFObject.h ================================================================== --- src/OFObject.h +++ src/OFObject.h @@ -640,11 +640,11 @@ * \brief Compares the object with another object. * * \param object An object to compare the object to * \return The result of the comparison */ -- (of_comparison_result_t)compare: (id)object; +- (of_comparison_result_t)compare: (id )object; @end #import "OFObject+Serialization.h" #ifdef __cplusplus Index: src/OFString.m ================================================================== --- src/OFString.m +++ src/OFString.m @@ -1139,11 +1139,11 @@ - mutableCopy { return [[OFMutableString alloc] initWithString: self]; } -- (of_comparison_result_t)compare: (id)object +- (of_comparison_result_t)compare: (id )object { void *pool; OFString *otherString; const of_unichar_t *unicodeString, *otherUnicodeString; size_t i, minimumLength; @@ -1154,11 +1154,11 @@ if (![object isKindOfClass: [OFString class]]) @throw [OFInvalidArgumentException exceptionWithClass: [self class] selector: _cmd]; - otherString = object; + otherString = (OFString*)object; minimumLength = ([self length] > [otherString length] ? [otherString length] : [self length]); pool = objc_autoreleasePoolPush(); Index: src/OFString_UTF8.m ================================================================== --- src/OFString_UTF8.m +++ src/OFString_UTF8.m @@ -690,11 +690,11 @@ return NO; return YES; } -- (of_comparison_result_t)compare: (id)object +- (of_comparison_result_t)compare: (id )object { OFString *otherString; size_t otherCStringLength, minimumCStringLength; int compare; @@ -704,11 +704,11 @@ if (![object isKindOfClass: [OFString class]]) @throw [OFInvalidArgumentException exceptionWithClass: [self class] selector: _cmd]; - otherString = object; + otherString = (OFString*)object; otherCStringLength = [otherString UTF8StringLength]; minimumCStringLength = (s->cStringLength > otherCStringLength ? otherCStringLength : s->cStringLength); if ((compare = memcmp(s->cString, [otherString UTF8String],