fortran 128 bit precision
16 views (last 30 days)
Show older comments
I have code that I want to port from fortran into Matlab hopefully. Does the new 2012a Matlab, 64Bit, have a true "REAL*16" long double type cast?
If so, how do you type cast a variable to be a specific size? e.g; REAL*8 or Real*16 for 64bit and 128bit respectively. I have a stiff differential solver program written for the CRAY and its convergence criteria requires this precision. Without re-writing for Windows 7, Fortran and hoping, I thought MATLAB 64 would be a good platform due to the high number of matrices written.
Thanks ahead of time, Bill
0 Comments
Accepted Answer
Ben Barrowes
on 8 Mar 2012
To convert your code to matlab, f2matlab will help. It will do about 90% or more of the work for you. http://www.mathworks.com/matlabcentral/fileexchange/5260
Once you are in matlab, you can use the higher precision solutions above. In terms of more alternatives, you could use the multiple precision toolbox: http://www.mathworks.com/matlabcentral/fileexchange/6446 but that will be slow compared to even matlab code.
or the Mathematica interface if you happen to have mathematica: http://www.mathworks.com/matlabcentral/fileexchange/6044
If you need speed and real*16, just leave it in fortran if that works for you. It should be able to compile on a windows platform. You say you tried for 3 months, so it seems like there is some problem, but it should work and we or others in fortran forums should be able to help. Otherwise a mex interface is a good idea to preserve speed but add a matlab interface. In the mex case, your numbers will be converted down to doubles when they return to matlab.
bb
0 Comments
More Answers (6)
Andrew Newell
on 6 Mar 2012
The default numerical type is double, which has 53 bit precision (the other 11 bits being for exponents and sign). If you have the Symbolic Toolbox or Maple Toolbox, you could use vpa to get any desired precision - at a cost in speed.
EDIT: See also Variable-precision arithmetic. For those without the Symbolic Toolbox, there is a function you can download from the File Exchange (see Variable precision arithmetic without the Symbolic Toolbox). Variable precision arithmetic is implemented by software, which is why it is not tied to the number of bits in the hardware (see this Wikipedia article).
0 Comments
Bill Swain
on 6 Mar 2012
2 Comments
Walter Roberson
on 6 Mar 2012
vpa should be good up to 100,000 or more digits. However, you might have trouble finding stiff solvers that operate within the symbolic toolbox.
It is _not_ possible to simply create a symbolic number and pass it around to the MATLAB numeric routines.
James Tursa
on 6 Mar 2012
Are you trying to create a mex routine from your Fortran code (e.g. using Intel ifort) that does the 128-bit floating point calculations? Or are you trying to convert all the Fortran code to m-code? Without extras such as the Symbolic Toolbox, 64-bit is the largest floating point type supported. E.g., you aren't going to find any 128-bit BLAS or LAPACK routines for background linear algebra calculations shipped with MATLAB (if that even applies to your code). You could do all the 128-bit calculations inside a mex routine and then use MATLAB for display, plotting, etc purposes.
0 Comments
Bill Swain
on 6 Mar 2012
1 Comment
James Tursa
on 7 Mar 2012
If you have working ifort Fortran code that uses 128-bit floats, I would opt to write a mex routine as a first choice. That being said, I still don't completely understand your situation. What does MATLAB have to do with any of this? Are you simply trying to move your Fortran code to *something*, *anything*, that will work on a Windows 7 platform and preserve your 128-bit floating point calculations? And something in your code doesn't work in your current Windows setup? What does "couldn't accept anything bigger than 80 bits" mean? What, exactly, is not working? I can easily write ifort Fortran code that uses 128-bit floats inside a mex routine and interface that to MATLAB on my 32-bit WinXP machine. I just don't understand what your real problem is yet. P.S. Windows and MATLAB being "64-bit" is an operating system and application thing. It mainly has to do with things like addressing space and pointer sizes, not floating point types that are available to the application. The latter will be dictated by the h/w and compiler used.
Jan
on 7 Mar 2012
You can create a QFLOAT type using the library of the LCC compiler. You need a version from the net, not the outdated version shipped with Matlab/32. QFLOATs have 348 bits (about 104 digits) and the library is well tested and contains SIN, ERF, POWER etc also.
If the standard operators are defined e.g. in a folder called @qfloat, even the standard numerical methods (integrator, optimisation) should work seamlessly in Matlab.
I've implemented such a set of functions for SINGLE and INT64 arithmetics for Matlab 6.5. I took some hours only. For QFLOATs the ouztput to the command window or to files will be more complicated, but solvable. For QFLOATs the XSUM function from the FEX is 50 times slower than for DOUBLEs.
Anyhow, it is not usual, that a convergence requires such a high precision. There is simply no physical meaning of such high precision values anymore.
0 Comments
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!