EDIT : Thanks for your very fast answers !
I do understand how the numbers are represented, and why such a result can be observed. My question really is about a way to make them add up to 1.0.
I have an alphabet of 4 letters A, C, G and T.
I counted them up, thus have the total letter count and each individual count.
unsigned int A_count; //initialized
unsigned int C_count; //initialized
unsigned int G_count; //initialized
unsigned int T_count; //initialized
//a bit hacky, enables floating point division
double total_count = A_count + C_count + G_count + T_count;
Then, I try to compute their frequency :
double A_frequency = A_count / total_count;
double C_frequency = C_count / total_count;
double G_frequency = G_count / total_count;
double T_frequency = T_count / total_count;
But this doesn't always work for me because the sum of the frequencies can be greater than 1, and I need it to be equal to 1.0 exactly.
Exemple :
std::cout << "Result : " << A_frequency + C_frequency + G_frequency + T_frequency << std::endl;
Result : 1.000[...]01
I need it to generate a meme file as documented here (MEME file format).
One can read in the relevant part that :
As each row contains the probability of each letter in the alphabet the probabilities in the row must sum to 1.
As @TonyK pointed out in the comments, the MEME file itself doesn't need the sum to be exactly 1.0, despite what the documentation says.
But in my case, the meme file is just created to be the input of another program which needs the sum of the frequencies to be exactly 1.0.
Is there any good/pretty way to do it ? If there isn't, why ?
(This is my very first post on stackoverflow, if something is wrong with it, please tell me and I'll correct it, thank you)