Hello(adsbygoogle = window.adsbygoogle || []).push({});

I am currently using double type for numbers with the format 6f8 (6 digits before the point, 8 digits after the point).

Double structure is enough for this format, or should I use int64_t instead?

Thank you in advance :)

Greetings.

PS: I tried with this example code, but the result it's a bit strange for me... (precision is lost for 4-digit double ? )

http://cpp.sh/8zqfxCode (C):

#include <iostream>

#include "stdint.h"

int main()

{

std::cout << "check precision of Double vs uint64_t\n";

uint64_t k(1);

while( k < 1e14 )

{

k=k*3+1;

//-- check precision of myDouble

double myDouble( k/1e8);

uint64_t test( 1e8 * myDouble );

if( k != test ) std::cout << k << "\t" << test << std::endl;

}

return 0;

}

The output I got is:

check precision of Double vs uint64_t

3280 3279

3812798742493 3812798742492

**Physics Forums - The Fusion of Science and Community**

The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

# C/++/# Precision double in C/C++?

Have something to add?

Draft saved
Draft deleted

Loading...

Similar Threads - Precision double | Date |
---|---|

C/++/# Need more precision in the calculations... | Aug 14, 2016 |

Fortran Modern variable precision and integer multipliers | Mar 16, 2016 |

Real vs. double precision in Fortran 90? | Aug 1, 2011 |

How to get first digit of a double precision number? | Nov 1, 2009 |

Double precision computation time in fortran | Sep 12, 2007 |

**Physics Forums - The Fusion of Science and Community**