Re: flummoxed by math failure
Re: flummoxed by math failure
- Subject: Re: flummoxed by math failure
- From: Karl Kraft <email@hidden>
- Date: Wed, 23 Jul 2003 17:25:05 -0500
In coding, nothing is ever trivial. When you come across what appears
to be a broken compiler or code that doesn't compute correctly, the
problem is usually occurring far before the part that is generating the
output.
Your problem is that rate is not a NSDecimalNumber. It is most likely
an NSString.
Did you declare it as id or NSDecimalNumber* ?
How did you assign the value to rate?
Sample code to demonstrate:
#import <Cocoa/Cocoa.h>
int main(int argc, const char *argv[])
{
NSAutoreleasePool *p =[[NSAutoreleasePool alloc] init];
id hours=[NSDecimalNumber decimalNumberWithString:@"1"];
id rate1 =[NSDecimalNumber decimalNumberWithString:@"100"];
id rate2 =@"100";
NSLog(@"%@ X %@ = %@", hours, rate1 , [hours
decimalNumberByMultiplyingBy:rate1]);
NSLog(@"%@ X %@ = %@", hours, rate2 , [hours
decimalNumberByMultiplyingBy:rate2]);
[p release];
return 0;
}
Sample Output:
2003-07-23 17:23:15.693 nsdf[12908] 1 X 100 = 100
2003-07-23 17:23:15.709 nsdf[12908] 1 X 100 = 0
--
To purchase it is not like spending money
but rather it is an investment in the future
in a blow against the empire
On Wednesday, Jul 23, 2003, at 01:04 US/Central, Dean G. Tresner wrote:
>
I had several responses like Angela's and I'm sorry, I was a bit
>
tired. These were just trivial accessor methods of the object being
>
implemented here so I wasn't bothering to be consistent. Just to make
>
sure, I edited the code snippet to use the two (NSDecimalNumber *)
>
members directly:
>
>
NSDecimalNumber *t;
>
t = [hours decimalNumberByMultiplyingBy:rate]; //
>
withBehavior:numBehavior];
>
NSLog(@"%@ X %@ = %@", hours, rate , t);
>
>
Which gave the same results.
>
>
As to whether this is an autorelease issue, I don't see how--hours and
>
rate are continuing to report their correct values, and I commented
>
out the withBehavior: argument specifically to rule out an autorelease
>
issue there.
>
>
Dean
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.