Hello Olivier,

I am working with NSDecimals and ran across your 7 year old post in
Cocoa-dev. Did you ever get an answer to your mantissa question? The
archives do not show a response to the thread.

Btw, did you consider NSData's

+dataWithBytes:length:

method?

NSData *anNSDecimalAsData = [NSData dataWithBytes:&anNSDecimal
length:sizeof(NSDecimal)];

gives you an NSData object suitable for an NSDictionary without having to
muck around with NSDecimal's private fields.



++ Tom

Tom Bernard
tombern...@bersearch.com




> --__--__--
> 
> Message: 11
> Date: Tue, 29 Oct 2002 12:37:35 -0600
> Subject: extracting the mantissa for a NSDecimal
> From: Olivier <...>
> To: cocoa apple <...>
> 
> i'm trying to save an NSDecimal in a dictionary.
> 
> I study the NSDecimal structure and decided that all i really need to
> save are:
> _exponent,  _isNegative  and  _mantissa  field
> 
> i'm trying to get the mantissa field, i want to store it as a NSNumber
> in my dictionary.
> 
> the length field of the NSDecimal tells how many short of the mantissa
> are relevant
> 
> so i'm building my data this way:
> 
>              NSMutableData *theNumberData = [NSMutableData
> dataWithLength:16];
>              for (i = 0; i < valueOfObject._length; i++)
>              {
>                  [theNumberData replaceBytesInRange: NSMakeRange(16 -
> (i+1) * 2, 2)
>                                           withBytes:
> &valueOfObject._mantissa[i]];
> 
>              }
> 
> so that the relevant field are put in the data object starting from the
> end of the object (most significant bytes first)
> 
> then start the problem, converting it to an NSNumber i tried:
> 
> const char *theNumberPtr = [theNumberData bytes];
> [NSNumber numberWithUnsignedLongLong: *theNumberPtr]
> [NSNumber numberWithUnsignedLongLong: theNumberPtr[0]]
> [NSNumber numberWithUnsignedLongLong: &theNumberPtr]
> 
> without any success.
> 
> Any idea of how to get that mantissa in a NSNumber?
> 
> Olivier
> 
> --__--__--


_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to