And*_*ndy 1 python precision fortran double-precision f2py
我似乎无法使用 f2py 创建模块来将数字传回 python 时保持双精度。一个最小的例子,带有文件 fmodules.f90:
subroutine example(output)
implicit none
double precision :: output
cf2py intent(out) :: output
output = 1.3
end subroutine example
Run Code Online (Sandbox Code Playgroud)
然后我使用 f2py 创建模块:
$ f2py -c -m fmodules fmodules.f90
Run Code Online (Sandbox Code Playgroud)
并从 python 中调用它:
>>> from fmodules import example
>>> example()
1.2999999523162842
Run Code Online (Sandbox Code Playgroud)
根据我的计算,精度约为 8 位数字。我的印象是双精度应该给出大约 16。我已经尝试了我能想到的所有排列,包括处理文件.f2py_f2cmap。对我所缺少的有什么想法吗?
您应该使用双精度在 Fortran 代码中设置输出,
output = 1.3d0
Run Code Online (Sandbox Code Playgroud)
在 Fortran 1.3 中是单精度常量。
| 归档时间: |
|
| 查看次数: |
464 次 |
| 最近记录: |