MATLAB double addition format long
26 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
vivek patel
il 3 Nov 2022
Modificato: Stephen23
il 3 Nov 2022
Why does the below addition show wrong output when i use the format long option ?
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1179628/image.png)
1 Commento
Stephen23
il 3 Nov 2022
Modificato: Stephen23
il 3 Nov 2022
"Why does the below addition show wrong output when i use the format long option ?"
Why do you think that it is a "wrong output" ?
Can you show us any double floating point number that is closer to the value 14.2?
format hex
14.2
format long
14.2
N = hex2num({'402c666666666665','402c666666666666','402c666666666667'})
fprintf('%.50f\n',N)
Risposta accettata
Più risposte (1)
VBBV
il 3 Nov 2022
format long
x = 14.1 %
x = 0.1
x = 14.1 + 0.1 % when you include + operator
When a mathematical operator /computation is used between any two numbers, Matlab uses its floating point arithmetic precision to compute precisely, Notice the difference in outputs when individual numbers are present without operators !
0 Commenti
Vedere anche
Categorie
Scopri di più su Logical in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!