格式化功能的双精度 [英] Double precision in FORMAT function

查看:58
本文介绍了格式化功能的双精度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Fortran中没有任何编程经验,但是对于我在学校中的一门课程,我们必须将程序从Fortran转换为Java.我遇到问题的代码行是

I don't have any programming experience in Fortran, but for one of my courses at school we have to translate a program from Fortran into Java. The line of code that I'm having an issue with is

 295   FORMAT(1X,'Y(X) =',D25.16,' * X ',A1,D25.16,///)

我认为不一定需要整行,但我想针对某些情况给出整行.说 D25.16 的那部分让我大吃一惊,因为我似乎在任何地方都找不到关于此的任何信息.我原本以为它正在格式化双精度数字,以便能够在.(点)的左侧保留25位数字,而在右侧保留16位数字,但是我似乎找不到关于这意味着什么的任何信息,并且不知道我对此是否正确.我只是在看是否有人可以对此做些了解.

I don't think the entire line is necessarily needed, but I wanted to give the whole line for some context. The part that says D25.16 has kind of thrown me off since I can't seem to find any information about this anywhere. I was originally thinking it was formatting a double precision number to be able to have 25 digits on the left side of the .(dot) and 16 digits on the right, but I can't seem to find any information on what that means and don't know if I'm for sure right or wrong about that. I was just seeing if anyone could give some insight to what that does.

推荐答案

D 编辑描述符与 E 编辑描述符密切相关(可能更容易找到阅读有关的材料,但与注释中提到的 F 编辑描述符不同.

The D edit descriptor is closely related to the E edit descriptor (which may be easier to find reading material about), but is distinct from the F edit descriptor mentioned in a comment.

E D 指定实数将显示为指数.对于使用 E 的输出,数字可以写为

E and D specify that the real number will be presented with an exponent. For output using E a number may be written as, say,

+0.1234e+12

对于 D25.16 ,您正确的是小数点后的位数是16(很好,是小数部分),但是字段的总宽度是25,而不是左边的位数.[左侧是 0 或什么都没有.]字段宽度由(强制性)符号,(可选)前导0,(潜在可选)指数标记,(强制性)指数贡献.符号,以及(至少)两个指数数字.

For D25.16 you are correct that the number of digits after the decimal point is 16 (well, the fractional part), but it is the overall width of the field that is 25, not the number of digits to the left. [To the left is either a 0 or nothing.] The field width has contributions from the (obligatory) sign, (optional) leading 0, the (potentially optional) exponent marker, the (obligatory) exponent sign, and (at least) two exponent digits.

如果有三个指数位,则缺少指数标记(导致出现诸如 .1234 + 110 之类的东西).

If there are three exponent digits then the exponent marker is missing (leading to such things as .1234+110).

D E 之间存在差异:

  • D 不允许指定指数宽度(参见 E15.5E5 );
  • D 允许(但不强制)使用 D 作为指数标记(而不是 E ).
  • D doesn't allow specification of the exponent width (cf., E15.5E5);
  • D allows (but doesn't oblige) use of D as the exponent marker (instead of E).

这篇关于格式化功能的双精度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆