Hi everyone!
I want know what's difference between 'd' and 'e' in matlab.
Sincerely, JH Jung

 Réponse acceptée

Walter Roberson
Walter Roberson le 14 Fév 2014

2 votes

Historical support. I don't think the "d" form is even documented now. The "D" form was common in FORTRAN in the 1960's.

1 commentaire

JiHun Jung
JiHun Jung le 17 Fév 2014
Walter Roberson, Thank for your answer!

Connectez-vous pour commenter.

Plus de réponses (1)

Jan
Jan le 14 Fév 2014
Modifié(e) : Jan le 24 Fév 2021

1 vote

Last year the technical support answered, that the following number formats are working, but not documented:
2.
.2
.2e3
.2e+03
-.2E3
2d3
.2e2.*2.
2..*.2

5 commentaires

JiHun Jung
JiHun Jung le 17 Fév 2014
Jan Simon, Thank for your answer!
Yukteshwar Baranwal
Yukteshwar Baranwal le 23 Fév 2021
@Jan @ So whether I use "e" or "d" both are same? Also, are both related to double precision?
John D'Errico
John D'Errico le 23 Fév 2021
Modifié(e) : John D'Errico le 23 Fév 2021
Yes. Either is fine. You always get the same result, a double precision number. d and e are essentially synonyms. They go back to long ago, to the roots of MATLAB, when Fortran allowed both forms for numbers. Even in Fortran they were essentially synonyms.
I would stick with e however, avoiding the d syntax. Undocumented features can sometime disappear in later releases. So sometime in the deep future, when all of us old people who remember what d does are dead and gone, they might decide to make things simpler and just remove support for a feature that nobody needs anyway.
FORTRAN E format was (originally) single precision for constants and D format was double precision. For example
COMMON/ABC/3.2e-1,3.2d-1/
initialized a single precision followed by a double precision
Jan
Jan le 24 Fév 2021
@Yukteshwar Baranwal: As I have written in my answer, I've asked the support, because I did not find an explanation in the documentation, if the mentiones notations are accepted.
Tme MathWorks answered, that only the formats are guaranteed to work, which are created as output of sprintf(). Therefore I do not use leading or trailing dots in numerical constants and stay at "e" or "E" for the exponent.
Nevertheless, fscanf accepts these notations and M-code is interpreted correctly also. But I stay at the documented syntax, because this is no drawback.

Connectez-vous pour commenter.

Catégories

En savoir plus sur Fortran with MATLAB dans Centre d'aide et File Exchange

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by