Double Accuracy

This is a discussion on Double Accuracy within the C++ Programming forums, part of the General Programming Boards category; How accurate are the results of this app?
Code:
#include <iostream>
#include <conio>
using namespace std;
void _In_Out()
{
int ...

That depends entirely on the particular architecture this is running under. But if I were to venture a guess, I'd say no: on the typical x86, double is a 64-bit-wide type. If it was integral (it isn't), it could represent at most 2^64 with integral accuracy. A hypercube in 255 dimensions with 99999999 side length each would have a hypervolume (or whatever it's called) of 99999999^255. Obviously, that's quite a bit more than can possibly be represented accurately.

There are arbitrary precision math libraries that can do what you want.

Note that the program is actually malformed, because names starting with an underscore followed by an uppercase letter are reserved for the compiler and standard library implementation.

Dave : I would do that only I have absolutely no idea what to 'expect' the result to be :P

robatino : I think that line is okay, when the array is initialised it has some random value in it, only when it reaches the end of the array (or if the user entered 0 for one of dimensions by accident) will it break.

CornedBee : I see I'll just have to make a note to the user in the programs introduction.

If a variable is uninitialized, you can't make any assumptions about what it is, or isn't, equal to. Period. It could be equal to any possible value. If you want to guarantee that it's not 0, you need to explicitly set it to a nonzero value.

I see, this seems to run fine for me every time though. What should I replace that with? Can I check against Null instead of 0?

You remove it without replacement. Then you correct the loop index (array indices go from 0 to length-1, but your array loops from 1 to length).
If you want to ensure that the user doesn't enter more than 255 sides, you validate the value of sides before the loop. Truncate it to 255 and inform the user that it has been truncated. Or skip the entire loop, because if the user wanted a 300-dimensions cube, he won't be happy at being able to calculate a 255-dimensions cube.

Speaking of which, the term "side" is slightly inappropriate, I think. Though I've never formally learned about the terminology.

Good point by iMalc about not storing all the values, too.
But in Visual C++, double and long double have the same precision.

Another method to avoid overflow is to use the fact that the log of the product is equal to the sum of the logs. If you add up the base 10 logs of each side, the sum is equal to the base 10 log of the product. Then the integer part of this number is equal to the exponent, and 10 raised to the fractional part is the mantissa. For example, if the sum is 127.653, the mantissa is 10^(0.653) = 4.4977... and the exponent is 127, so the product is 4.4977 * 10^127.

Edit: For this to work, each side has to be a positive number. Also, the fractional number you use to get the mantissa has to be between 0 and 1 to get your output in standard scientific notation, so for example if the sum of the logs was -5.3, you would have to write this as 0.7 + (-6). Since 10^(0.7) = 5.0118..., the product would be 5.0118 * 10^(-6).