I want to save a sequence of double into a .txt file, and read them later on in C. How can I achieve this without precision loss? What I don't know to do is how many digits I need to save? I doubt I may not get the exact double I saved if not enough digits are saved.
Below is what I have tried
doubles=[3.14159, 3.14159265358]
filename="tmp.txt"
with open(filename,'w') as f:
for x in doubles:
f.write("%.16f\n" %x)
I got two (I guess) imprecise representation of my data, doubles
.
3.1415899999999999
3.1415926535800001
This is undesirable. I want data to be stored as is, so that another program can retrieve them exactly. Any idea?