I have a some doubles that I want to port into NSDecimalNumber, because I'm getting too bad floating-point arithmetic errors with them.
They are:
double one = 0.0000001;
double two = 1000000000.0000001;
They are very problematic, but I hope that NSDecimalNumber can help out to get calculations right. I'm not that big math genius, so I wonder how to provide the correct input to this method of NSDecimalNumber.
Let me try:
NSDecimalNumber *one = [NSDecimalNumber decimalNumberWithMantissa:1 exponent:-7 isNegative:NO];
NSDecimalNumber *two = [NSDecimalNumber decimalNumberWithMantissa:10000000000000001 exponent:-7 isNegative:NO];
I feel that's wrong. I could only guess. The documentation does not provide much information on that. But as far as I get it, the "mantissa" is an integer and the exponent tells where the floating point should be, by adding zeros. Probably this is also wrong ;-)
I have seen some code snippets where people just feeded a CGFloat as mantissa and provided a 0 as exponent, but I can only guess what their intention was, so I can't just do it the same way without understanding it.
Any idea?