How can I avoid a small value ignored during calculation?
이전 댓글 표시
z is a small value, and wen a1 is added by z, it doesn't show any difference. Why is that? And how can I aviod this?

채택된 답변
추가 답변 (1개)
Patrik Forssén
2022년 11월 20일
편집: Patrik Forssén
2022년 11월 20일
@John D'Errico explained why this happens. If you really need to avoid this, you must therefore use an arbitrary-precision numerical class for your calculations. MATLAB does not have one, but you can interface Java’s. Here is what your example would look like,
z1 = java.math.BigDecimal('1.111111e-19');
a1 = java.math.BigDecimal('-0.0581375401465599531136696498379023978486657142639160156250000000000000');
a2 = a1.add(z1);
disp(char(z1.toPlainString()))
disp(char(a1.toPlainString()))
disp(char(a2.toPlainString()))
카테고리
도움말 센터 및 File Exchange에서 Logical에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!