Unfamiliar .D0 number syntax

21 ビュー (過去 30 日間)
Chad Greene
Chad Greene 2022 年 3 月 7 日
コメント済み: James Tursa 2022 年 3 月 9 日
I've inherited some Matlab code that was previously adapted from Fortran, and the Matlab code has a syntax I'm not familiar with. Numbers end with .D0, so I see a lot of lines like:
a = b*5.D0;
which produces the same result as
a = b*5;
I haven't found any documentation for this syntax, but it's easy to deduce what it's doing:
>> 12345.D0
ans =
12345
>> 12345.D2
ans =
1234500
>> 12345.D-3
ans =
12.3450
My questions are:
  1. What is this syntax called?
  2. Is there any particular reason to use it?
  3. Can I safely delete every instance of .D0 from this code I've inherited?

採用された回答

Steven Lord
Steven Lord 2022 年 3 月 7 日
This is E notation. I believe MATLAB supports D as well as E because Cleve was inspired by Fortran, which as a comment on that page states "FORTRAN (at least since FORTRAN IV as of 1961) also uses "D" to signify double precision numbers in scientific notation."
x = 3.4e2
x = 340
y = 3.4d2
y = 340
The .D0 indicates that whatever value you're defining is an integer. All of z, w, and q are the same value (five.)
z = 5.0D0
z = 5
w = 5.D0
w = 5
q = 5D0
q = 5
  2 件のコメント
Chad Greene
Chad Greene 2022 年 3 月 7 日
@Steven Lord Thanks, so I guess I can delete the .D0 instances from the code I inherited.
James Tursa
James Tursa 2022 年 3 月 9 日
@Chad Greene FYI, there is a difference between MATLAB and Fortran for the E notation. In MATLAB the E notation is a double variable same as D notation, but in Fortran the E notation is single precision, not double precision.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeFortran with MATLAB についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by