1, 2)
A floating point number can hold larger numbers than can the largest integer.
However, FP numbers are
not continuous. They are, at best, an
approximation to the the desired value. If you want arbitrary-precision numbers, I recommend you to the
GNU MP Bignum library
http://gmplib.org/
3)
The
setprecision() manipulator can be thought of as a function taking an argument affecting the state of an I/O stream. I'm not sure that using the braces is actually making any difference, or whether it should be expected to do that anyway. (But I'm not a language lawyer.)
You can read and restore the state of a stream (like
cout), but it is simply best to set your precision, fixed, etc before every set of operations operation that requires it to be that way. For an output operator, use
http://www.cplusplus.com/reference/iostream/ios_base/precision.html
to preserve the precision if you need to change it.
In your example, there is no reason to try to use it only locally.
4)
Typically, you would open the file in
main() instead of
getValues(), then put it all in a loop:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
|
inFile.open( ... );
// Get the first value (if any)
getValue( inFile, x );
while (inFile) // While there are values (or at least no errors)
{
// Calculate and display the Taylor series
expAnswer = expApprox( x );
displayResult( expAnswer, x );
// Get the next value (if any)
getValue( inFile, x );
}
inFile.close();
|
Notice how the file is passed as a variable reference to
getValue() as well as the result.
5)
To late to think that hard. Looks good enough to me.
Hmm, I'd probably return the value as
x = getValue( inFile );
Hope this helps.