I have a Fortran program which I have to convert into Java originally. I have converted the code completely but can't get appropriate resutls. The code contains lot of arithmetic calculations using double precision data type of Fortran.
I believe the data types of C++ and Java are based on same whereas of Fortran double precision is based on IEEE756. I want to know how to convert these double precision calculations into C++ normally. For example:
double precision d1 = 0.3648564D0;
d1**2 // ** indicates exponent
DSIN(d1) // sin of double precision
DCOS(d1) // cos of double precision
The above are my main concerns which I find very difficult to convert. I use sin & cos for DSIN & DCOS. But Fortran 77 deals somthing differntly with double precision. How to convert/translate that into our normal C++ application is what I am looking for.
If you can provide the same for Java that would be a plus for me, otherwise I will use the code accordingly of C++ in my Java application. I hope help from you.
You should either mark the Real and Imag fields as readonly, or make them public properties with private setters. You can append " : this()" to the constructor's signature to make C# allow property assignments in the constructor.
Can this run with Windows Forms instead of console? I tried adding complex.dll as a reference (in Visual Studio 2005) but got the following error ar runtime:
LoaderLock was detected
DLL 'C:\Documents and Settings\Bill\My Documents\Visual Studio 2005\Projects\TestComplex\TestComplex\bin\Release\complex.dll' is attempting managed execution inside OS Loader lock. Do not attempt to run managed code inside a DllMain or image initialization function since doing so can cause the application to hang.
First of all, it's managed C++. This could be written entirely using straight C#.
Secondly, why are you using std::complex?. You're instantiated the template using a double in the C++ section, so the C# and VB side doesn't benefit from the point of a template, which is to instantiate whatever type you want. Therefore, this supports the previous point that this should have been written in C# to begin with.
BTW, C++ doesn't inherently support complex types (last time I checked). This is provided by STL.
You might want to look at this link for some simplistic examples:
As this article discusses, you might also want to overload the equality operators so we can compare complex numbers.
Finally, as you say, there's a major performance hit using complex numbers with managed C++. If I were writing a complicated math function with lots of complex number calculations, I really wouldn't want to incur these performance hits.
Thanks for the comment.
You are right it could be in straight C# and that would be nice.
My goal was full functionality, which is where managed C++ is great. C# and VB get to use the STL indirectly to get full functionality. The tradeoff is losing some flexibility and performance in non trivial cases. For the easy cases I am NOT using STL!
I use STL to handle non-trivial cases letting it worry about significant bits, as needed. With time more functions could be converted away from the STL wrapper. At that point it would be an easy port to C# if desired.
I HAVE overloaded the equality and other operators. I was hoping for feedback on why I needed to create redundant functions like Equals() to make it work in VB. The overloaded stuff works great in C++ and C#, but not everything maps to VB.
Ok STL is not “built” into the language but any good C++ compiler has STL, hence you can do complex math with C++ and FORTRAN.