# Does C++ have instructions to allow extended precision in floating point operations?

This is a discussion on Does C++ have instructions to allow extended precision in floating point operations? within the C++ Programming forums, part of the General Programming Boards category; I understand that computers use 'floating point representation' to represent fractions and very large numbers. This form of storage is ...

1. ## Does C++ have instructions to allow extended precision in floating point operations?

I understand that computers use 'floating point representation' to represent fractions and very large numbers. This form of storage is vulnerable to all kinds of round off and significant figure errors.

One solution is 'extended precision' where the size of the word storing the floating point representation is doubled. I've read math programs like MATLAB give the user the options to use extended precision.

Does C++ have a keyword or function that instructs the computer to use extended precisions?

2. C++ has float, double and long double floating types.
Each should, if you are lucky, be larger than the previous, meaning it can hold larger numbers and better precision. But it's also up to the implementation and platform to decide what size they are.
If that won't do (which, IMHO, it does not), you can always implement your own class that fits the bill. There should be pre-developed such classes out on the web.

3. I suspect that you are talking about double. but of course since it is still a floating point representation, the problems remain. If you are talking about fixed point, then that would be different.

4. >> I understand that computers use 'floating point representation' to represent fractions and very large numbers. This form of storage is vulnerable to all kinds of round off and significant figure errors.

Floating-point is a way of representing *approximations* of fractional values. Rounding errors and the like are inevitable.

>> One solution is 'extended precision' where the size of the word storing the floating point representation is doubled. I've read math programs like MATLAB give the user the options to use extended precision.

That's not a solution. Given a sufficiently large or small number it too will exhibit rounding errors.

>> Does C++ have a keyword or function that instructs the computer to use extended precisions?

Most systems these days at the very least support 4-byte and 8-byte floating point numbers, and these would be mapped to C++'s 'float' and 'double' types, respectively. If you're system supports larger formats, you'd probably need to write some assembly to access it.

Having said that, if you wanted an even larger number you could of course implement it in software, and if you wanted to do it in a way that wouldn't accumulate errors you could simply store the values as pure fractions (numerator/denominator). Google big-float library or such.

5. Yes, I'd forgotton about large data types. Doubles or larger types probably automatically implement 'extended precision'.

Thanks for pointing out to me the possible software solutions. I should have known all those brains out there would have fixed these problems long ago. I did not realize, however, that the balky computer hardware was so flexible and responsive to these solutions.

I was concerned about the computer hardware, but it looks like with so many good software solutions I think I can just put in the latest hardware, and not worry about any special optimization.

6. In the end, it's just bits for the computer.
It's true, however, that hardware do not have native support for larger floating types, which makes software solutions "expensive" in terms of processor utilization.