Precision issue when comparing matlab output with c code output
Afficher commentaires plus anciens
I am trying to compare my c code output with matlab output. My results are matching up to 18th decimal points. When both matlab and c compiler uses ieee754 floating point format. Then why am I observing the difference. As matlab by default uses double precision, my c code is also using double data type.
6 commentaires
John D'Errico
le 26 Mar 2025
Modifié(e) : John D'Errico
le 26 Mar 2025
"My results are matching up to 18th decimal points."
Then what is the problem, since that is beyond the limit of double precision?
Anyway, you say you are observing a difference someplace, on some unspecified computation. But we cannot see inside your computer, to actually know what you did. If you like, we can try using the MATLAB crystal ball, but it is always foggy these days. I think I dropped mine on the floor too many times. But the MATLAB tarot cards are an option too if that fails.
OR, you can actually show us what you did, instead of a vague description of something that does not match up. Is there a good reason why you want to make it impossible for anyone to help you? Make it easy to get help.
dpb
le 26 Mar 2025
This may boil down to one of the issues in <the last thread on similar comparison>, comparing output values with inconsistent formatting/precision.
Although note @Vaishnavi that the i/o formatting routines will continue outputting characters ad infinitum, long past the actual internal precision of the data storage size limits.
James Tursa
le 26 Mar 2025
@Vaishnavi Please post a small complete example that demonstrates your problem.
Walter Roberson
le 26 Mar 2025
Also, it is potentially possible differences are due to the rounding mode in effect.
dpb
le 26 Mar 2025
If identical past the 15-16 digits of DP, though? That's what makes this one hard to figure...OP says agree precisely to 18 decimal places?
"18 decimal points" is not necessary the same as 18 digits of precision. For example,
A = 0.0000000000123456789478;
fprintf('%.19f\n', A)
might seem to be valid to 19 decimal places, if you count starting from the period.
Réponses (0)
Catégories
En savoir plus sur Logical dans Centre d'aide et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!