vit*_*aut 1 c floating-point fortran
0.8804418
在Fortran中打印常量
program hello
print *, 0.8804418
end program hello
Run Code Online (Sandbox Code Playgroud)
给出0.880441785
了C版本
#include <stdio.h>
int main() {
printf("%.10g", 0.8804418);
}
Run Code Online (Sandbox Code Playgroud)
0.8804418
在同一系统上打印(带有gfortran和gcc的Linux x86-64).为什么输出不同?请注意,提高精度printf
并不会改变输出.
默认情况下,Fortran的REAL
数字常量是单精度的 ; 但是,在C中,浮点文字具有双精度.
当您转换0.8804418
为单精度然后将其打印为double
C时,您将被0.8804417849
打印(演示)
float x = 0.8804418f;
printf("%.10g\n", x);
Run Code Online (Sandbox Code Playgroud)
Fortran的打印输出似乎是相同的数字.
Fortran的双精度REAL
数字语法使用后缀d
:
print *, 0.8804418d+0
Run Code Online (Sandbox Code Playgroud)
这打印0.88044180000000005
(演示).
归档时间: |
|
查看次数: |
110 次 |
最近记录: |