Re: NSNumber math?
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>) |