0

i have written a program and it works with 3D coordinates (i.e. x,y,z).

input data for my program was like

50903.85 21274.97 15.03 
50903.57 21274.96 15.08 
50903.33 21274.95 15.17 

and i got the output with some more columns. So, i got the same x,y,z for my output file.

50903.85 21274.97 15.03 
50903.57 21274.96 15.08 
50903.33 21274.95 15.17

so, my program works properly, i guess.

then, i used another data set, having more digits than the previous data,

512330.98 5403752.71 330.39 
512331.01 5403754.18 329.44 
512331.06 5403755.59 329.56 

and my output was like;

512331 5.40375e+006 330.39 
512331 5.40375e+006 329.44 
512331 5.40376e+006 329.56 

here, i am not able to get real values. and x values are also rounded. i cant think what should be the reason?

in my program, i used "double" for assigning variables for x,y,z values. SO, i would like to know what is the maximum numerical value that can be refereed to double?

if someone need to work with very long values, what should be the relevant variable?

Thomas Matthews
  • 56,849
  • 17
  • 98
  • 154
niro
  • 947
  • 3
  • 13
  • 30
  • Check out this page: http://www.cplusplus.com/reference/iostream/manipulators/setprecision/ and this one: http://www.cplusplus.com/reference/iostream/manipulators/scientific/ – Thomas Matthews Mar 03 '11 at 23:45

4 Answers4

1

Those numbers, such as 5.40375e+006, are another way of representing doubles. When they get sufficiently large, they are by default printed in scientific notation. 5.40375e+006 is 5.40375 * 10^6, or 5403750.

dappawit
  • 12,182
  • 2
  • 32
  • 26
1

Numbers aren't changing, you are just seeing a different notation change there. Perhaps you are using something other than %f to format your doubles? See printf format parameters.

Better yet, check out this StackOverflow question: How to avoid scientific notation for large numbers?

Community
  • 1
  • 1
Julio Gorgé
  • 10,056
  • 2
  • 45
  • 60
0

Have a look at this http://www.cplusplus.com/reference/clibrary/cfloat/

Morten Kristensen
  • 7,412
  • 4
  • 32
  • 52
0

Doubles have about 16 decimals of accuracy (source), so you shouldn't have any problem here, unless you're printing floats.

tugudum
  • 387
  • 1
  • 4