[ET Trac] [Einstein Toolkit] #1534: Bug in complex numbers

Einstein Toolkit trac-noreply at einsteintoolkit.org
Thu Feb 6 18:40:23 CST 2014


#1534: Bug in complex numbers
-----------------------+----------------------------------------------------
  Reporter:  eschnett  |       Owner:                     
      Type:  defect    |      Status:  new                
  Priority:  critical  |   Milestone:                     
 Component:  Cactus    |     Version:  development version
Resolution:            |    Keywords:                     
-----------------------+----------------------------------------------------

Comment (by eschnett):

 I checked: On a 32-bit system, C and Fortran use the same calling
 convention, and C++ differs. Thus it seems we can't use C++ complex
 numbers.

 We currently typedef CCTK_COMPLEX differently in C and C++. I believe we
 need to change this, using "_Complex double" in both languages. Otherwise,
 e.g. a user-defined C routine returning CCTK_COMPLEX would fail when
 called from C++ and vice versa.

 The best solution I can come up with is to introduce routines to the flesh
 that convert from/to CCTK_COMPLEX and complex<CCTK_REAL>. User code would
 then have to call these explicitly when accessing grid functions.

 We can also introduce a new type CCTK_COMPLEX_CXX (namely
 complex<CCTK_REAL>), and use it to declare complex grid functions in C++.
 We can define this type even for C (as a struct, which has the correct
 memory layout). However, this would probably lead to trouble with header
 files included from both C and C++. I don't think this is a good idea.

 As mentioned above, the standard operators should work in C++ even for C
 complex types (_Complex double). We could provide our own overloads of
 std::abs for these, so that C++ code "would not notice". Maybe these
 overloads should be in the cctk namespace instead.

-- 
Ticket URL: <https://trac.einsteintoolkit.org/ticket/1534#comment:5>
Einstein Toolkit <http://einsteintoolkit.org>
The Einstein Toolkit


More information about the Trac mailing list