How can I avoid a small value ignored during calculation?
Ältere Kommentare anzeigen
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?

Akzeptierte Antwort
Weitere Antworten (1)
Patrik Forssén
am 20 Nov. 2022
Bearbeitet: Patrik Forssén
am 20 Nov. 2022
@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()))
Kategorien
Mehr zu Logical finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!