1

I can't seem to get my module created with f2py to keep a number at double precision when it is passed back to python. A minimal example, with file fmodules.f90:

      subroutine example(output)
              implicit none
              double precision :: output
cf2py         intent(out) :: output
              output = 1.3
      end subroutine example

I then create the module with f2py:

$ f2py -c -m fmodules fmodules.f90

and call it from python:

>>> from fmodules import example
>>> example()
1.2999999523162842

By my count, that's about 8 digits of precision. My impression was that double precision should give about 16. I've tried all the permutations of this I can think of, including playing with the .f2py_f2cmap file. Any ideas on what I am missing?

Andy
  • 131
  • 3
  • 1
    See http://stackoverflow.com/questions/3331818/does-fortran-have-inherent-limitations-on-numerical-accuracy-compared-to-other-l/3332069 and http://stackoverflow.com/questions/16992131/precision-of-real-variable/16997380 – M. S. B. May 06 '14 at 21:25

1 Answers1

5

You should set output in the Fortran code using double precision,

output = 1.3d0

In Fortran 1.3 is a single precision constant.

Fortranner
  • 2,525
  • 2
  • 22
  • 25