Re: double: Decimal places
Re: double: Decimal places
- Subject: Re: double: Decimal places
- From: mathew <email@hidden>
- Date: Wed, 16 Jul 2003 22:44:27 -0400
On Tuesday, July 15, 2003, at 07:37 AM, Cyprien wrote:
I'm trying to have at least 9 decimal places with the numbers I
manipulate. I use double, which garanties normally at least 15 decimal
places.
Assuming you want your 9 decimal places to be accurate, floating point
is not the answer, unless you have some fairly low upper bounds on the
numbers you might need to handle. Double doesn't guarantee 15 decimal
*places*; it guarantees 15 decimal *digits* of accuracy. So if you
want to represent 123456789.123456789 (say) you're out of luck.
(See <URL:
http://babbage.cs.qc.edu/courses/cs341/IEEE-754.html> if you
want to test this assertion.)
So if you really need 9 decimal places of accuracy, rather than 9
decimal digits of accuracy, and if your numbers may get significantly
larger than a million or so, then you may need to implement fixed point
(arbitrary precision) math, or find a fixed point math library
somewhere.
Beware also that not all decimal numbers with 9 decimal places will
have accurate finite length binary double float representations.
mathew
_______________________________________________
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.