Precision issue when comparing matlab output with c code output
显示 更早的评论
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 个评论
John D'Errico
2025-3-26
编辑:John D'Errico
2025-3-26
"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
2025-3-26
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
2025-3-26
@Vaishnavi Please post a small complete example that demonstrates your problem.
Walter Roberson
2025-3-26
Also, it is potentially possible differences are due to the rounding mode in effect.
dpb
2025-3-26
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.
回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Logical 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!