• 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 math?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSNumber math?


  • Subject: Re: NSNumber math?
  • From: Thilo Ettelt <email@hidden>
  • Date: Thu, 11 May 2006 16:37:19 +0200

Hello,

try NSDecimalNumber -> see the docs.


- Thilo

Am 11.05.2006 um 16:32 schrieb Christopher Hickman:

I take it that NSNumber instances are immutable, given that I can't find any
way to do math with them directly.


For example, this:

/* code snippet 1 */
int x = 1;
int y = 2;
int z;

z = x+y; //z == 3
/* end code snippet */

When using NSNumbers has to go to the way more complex:

/* code snippet 2 */
NSNumber *x = [NSNumber numberWithInt:1];
NSNumber *y = [NSNumber numberWithInt:2];
NSNumber *z;

z = [NSNumber numberWithInt:[x intValue] + [y intValue]]; //z == 3 as
NSNumber
/* end code snippet */

z = x+y is an error for the second one, since that would just be pointer
math--not good ;)


Are there some methods for performing math on NSNumbers that I'm just not
seeing in the docs? Something like -[NSNumber add:] or -[NSNumber
subtract:], etc.? Or do I have to pull the scalars out of their comfortable
little wrappers each time I have to do some math?


Topher

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden

_______________________________________________ Do not post admin requests to the list. They will be ignored. Cocoa-dev mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: This email sent to email@hidden
References: 
 >NSNumber math? (From: "Christopher Hickman" <email@hidden>)

  • Prev by Date: remove horizontal lines firstColumn ?
  • Next by Date: Re: NSNumber math?
  • Previous by thread: NSNumber math?
  • Next by thread: Re: NSNumber math?
  • Index(es):
    • Date
    • Thread