views:

219

answers:

4

I always thought it's double, until I accidently hit floo+ESC and it told me there is a floorl(<#long double #>) function. So long double is the solution to all big inaccuracy problems? ;-)

Or is there even something more precise than that?

+3  A: 

I think long double is the limit, but it really depends what you want to do. Have you actually been running into inaccuracy problems?

jtbandes
well, in theory I did ;-) but I don't want to in practice.
HelloMoon
What does that meant? There's no such thing as an inaccuracy problem in theory. Inaccuracy is a problem with practical implementations.
jprete
Only a computer with infinite memory can store the precise value of an arbitrary real number. If your application can perform calculations on arbitrary numbers, you either have to accept that there will be a loss of precision in some cases or invent a machine that has infinite memory ;)
rpetrich
+2  A: 

For even more precision look at the NSDecimalNumber class. As the other comment says - have you found any inaccuracy problems. Also more accuracy will be slower.

Mark
It's more precise but it's also performing different math, to my limited knowledge.
jtbandes
Math is math. It's just being more accurate about the result unlike floating point numbers where various degrees of (very small and well-defined) fudging is going on.For anything financial, you had better be using decimal number classes of some sort...
Kendall Helmstetter Gelner
+1  A: 

Adding more precision is one approach to solving the problem, but the real problem sometimes (usually?) lies in the way you are performing the computation. In that case, I proscribe a healthy dose of RTFM. Any primer on FP arithmetic will cover why certain forms of equations are disastrous and how to avoid the gaping maw of oblivion.

+2  A: 

One thing to be aware of is that long double simply acts as double on the iPhone hardware. You don't get any additional precision from the larger type. It will give you more precision in the Simulator, because you're running on a Mac there, so that can confuse you.

As is noted here (and by other commenters), NSDecimal or NSDecimalNumber is the way to go for precision (up to 34 digits), and calculations performed using it are done with true decimal math, not binary floating point. This avoids many of the errors that you see with normal IEEE 754 math.

Brad Larson