NSNumber compare: Giving Unexpected Results
NSNumber compare: Giving Unexpected Results
- Subject: NSNumber compare: Giving Unexpected Results
- From: Chris Tracewell <email@hidden>
- Date: Tue, 7 Sep 2010 17:58:08 -0700
I have a category on NSDecimalNumber that seems very straight forward - yet is producing odd results. The code below shows my logging and everything outputs as expected - but the final evaluation does not work. Am I misunderstanding something?
-(BOOL)isLessThanZero
{
NSNumber *theNumOne = [NSNumber numberWithInteger:0];
NSNumber *theNumTwo = self;
NSLog(@"theNumOne = %@",theNumOne);
NSLog(@"theNumTwo = %@",theNumTwo);
NSLog(@"NSOrderedSame = %d, NSOrderedAscending = %d, NSOrderedDescending = %d",NSOrderedSame,NSOrderedAscending,NSOrderedDescending);
NSLog(@"SHOULD SAME = %d",[theNumTwo compare:theNumTwo]);
NSLog(@"SHOULD ASCD = %d",[theNumOne compare:theNumTwo]);
NSLog(@"SHOULD DESD = %d",[theNumTwo compare:theNumOne]);
if ([theNumOne compare:theNumTwo] == NSOrderedDescending)
{
return YES;
}
return NO;
}
The above NSLogs produce.....
2010-09-07 17:52:52.559 TheApp[80337:a0f] theNumOne = 0
2010-09-07 17:52:52.559 TheApp[80337:a0f] theNumTwo = 191.2
2010-09-07 17:52:52.560 TheApp[80337:a0f] NSOrderedSame = 0, NSOrderedAscending = -1, NSOrderedDescending = 1
2010-09-07 17:52:52.560 TheApp[80337:a0f] SHOULD SAME = 0
2010-09-07 17:52:52.560 TheApp[80337:a0f] SHOULD ASCD = -1
2010-09-07 17:52:52.560 TheApp[80337:a0f] SHOULD DESD = 1
When I do the comparison from the controller instead of using the above category it works fine. Thanks in advance for any help.
--chris_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden