• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
NSNumber compare: Giving Unexpected Results
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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

  • Follow-Ups:
    • Re: NSNumber compare: Giving Unexpected Results
      • From: Kyle Sluder <email@hidden>
    • Re: NSNumber compare: Giving Unexpected Results
      • From: Quincey Morris <email@hidden>
  • Prev by Date: Re: Patching implementation in +load. Was: …Mapping Model : Spurious Warning
  • Next by Date: Re: NSEntityMigrationPolicy subclass methods not being called
  • Previous by thread: Re: recalling the original view height
  • Next by thread: Re: NSNumber compare: Giving Unexpected Results
  • Index(es):
    • Date
    • Thread