小编And*_*ndy的帖子

f2py 在传递给 python 时丢失双精度

我似乎无法使用 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。对我所缺少的有什么想法吗?

python precision fortran double-precision f2py

1
推荐指数
1
解决办法
464
查看次数

标签 统计

double-precision ×1

f2py ×1

fortran ×1

precision ×1

python ×1