• 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
Re: NSNumber compare: Giving Unexpected Results
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSNumber compare: Giving Unexpected Results


  • Subject: Re: NSNumber compare: Giving Unexpected Results
  • From: Quincey Morris <email@hidden>
  • Date: Tue, 7 Sep 2010 20:43:11 -0700

On Sep 7, 2010, at 17:58, Chris Tracewell wrote:

> -(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 message in the 'if' ([theNumOne compare:theNumTwo]) is an invocation of [NSNumber compare:], not [NSDecimalNumber compare:]. It's not absolutely clear what is supposed to happen when the compare parameter is an instance of NSDecimalNumber. Yes, NSDecimalNumber is a subclass of NSNumber, but these are abstract classes. The actual objects are (typically) concrete subclasses of the abstract classes, such as NSCFNumber. It's possible that this muddies the waters enough that the mixed comparison doesn't work as you would expect.

In any case, why not simply do the comparison between 'self' and '[NSDecimalNumber zero]'?


_______________________________________________

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

References: 
 >NSNumber compare: Giving Unexpected Results (From: Chris Tracewell <email@hidden>)

  • Prev by Date: Re: NSAttributedString to / from Pasteboard....
  • Next by Date: Re: What REALLY determines which application opens a file?
  • Previous by thread: NSNumber compare: Giving Unexpected Results
  • Next by thread: Re: NSNumber compare: Giving Unexpected Results
  • Index(es):
    • Date
    • Thread