Click to See Complete Forum and Search --> : Truncation of Digits with Double


Sid P.
August 11th, 2008, 04:05 PM
Hello,

I have two functions. The output of the first is input to the second. The both return double type numbers.

From within function one, I print out output of function one and the output of function two.

In main, I call function one, and using its output, then call function two. Again, I print out the two numbers.

In both cases the output of the first function appears to 6 decimal places only. The two numbers are identical for the digits presented. However, outputs of the second function are different.

This leads me to suspect the following: the output of the first function is truncated before being saved by the double created in main. So, the input to the second function is different in the two cases and because of this, the outputs of the second function was different.

Is this so? Or are there other possibilities for the outputs of the second function being different?

Also, if it is a matter of truncation, is there a way to ensure that all the digits of double type are used?

Thanks
Sid.

Lindley
August 11th, 2008, 04:10 PM
Truncation *only* occurs during outputs, or when a double is cast down to a float. In the output case, the value of the double remains unchanged no matter how many digits are written to the screen.

Sid P.
August 13th, 2008, 10:04 AM
Thanks Lindley.

As it turned out, the double number (output of first function) was not truncated (I displayed all 64 digits to check). The problem was that a parameter to the second function was different for the two cases.
Thats the reason for the different outputs of the second function.

Thanks again.

Lindley
August 13th, 2008, 10:18 AM
Doubles aren't accurate to 64 digits, FYI. The exact value of a double can be reconstructed with only 18 digits, and it's only accurate to something like 15.