Francisco Wechsler wrote:
Hello everybody: I am planning to use a few PASCAL programs for certain matrix manipulations. In the past, these subroutines were run in Turbo Pascal 6 or 7, with good numerical accuracy. Because the manual says that gpc doesn't pass the "paranoia" test, I have become a bit wary about running them in gpc. All subroutines are written in ISO PASCAL, and perform things such as: Cholesky decomposition, singular value decomposition, inversion etc. All variables are declared either as INTEGER or REAL. If memory serves me, in TP this means a 10-11 decimal digit mantissa for real numbers. Does anybody have experience in this regard? Am I being too "paranoid"?
I have only experience with gpc under djgpp (i.e. DOS). Djgpp has no extended precision libc or libm (long double in C, longreal in gpc, extended in BP: 10 bytes ), so that sin, cos, tan, exp, ln etc are only in double precision (8 bytes). In some case I had accuracy problems with respect to BP, for which all is computed internally in extended. To circumvent this I used the cephes "long double" library http://people.ne.mediaone.net/moshier/cephes28.zip
and the following import unit:
UNIT libml;
INTERFACE
function sqrt(x:LongestReal):LongestReal; Asmname 'sqrtl'; function exp(x:LongestReal):LongestReal; Asmname 'expl'; function ln(x:LongestReal):LongestReal; Asmname 'logl'; {operator pow(x:LongestReal,i:integer) r:LongestReal; Asmname 'powil';} {operator **(x,y:LongestReal) r:LongestReal; Asmname 'powl';} function sin(x:LongestReal):LongestReal; Asmname 'sinl'; function cos(x:LongestReal):LongestReal; Asmname 'cosl'; function tan(x:LongestReal):LongestReal; Asmname 'tanl'; function asin(x:LongestReal):LongestReal; Asmname 'asinl'; function acos(x:LongestReal):LongestReal; Asmname 'acosl'; function arctan(x:LongestReal):LongestReal; Asmname 'atanl'; function sinh(x:LongestReal):LongestReal; Asmname 'sinhl'; function cosh(x:LongestReal):LongestReal; Asmname 'coshl'; function tanh(x:LongestReal):LongestReal; Asmname 'tanhl'; function asinh(x:LongestReal):LongestReal; Asmname 'asinhl'; function acosh(x:LongestReal):LongestReal; Asmname 'acoshl'; function atanh(x:LongestReal):LongestReal; Asmname 'atanhl';
IMPLEMENTATION
{$L ml}
end.
Of course all variables are declared LongReal, identical to LongestReal in gpc/djgpp: to minimalize porting effort you may declare type real = LongReal at the beginning of the import library. (pow and ** are commented out because there are currently problems with redefining these operators in gpc. There is also a bunch of higher trancendental functions in this library which I have never used up to now) This library succeeds in the paranoia test and is superior to BP in all cases I have checked.
Notice that linux has built in long double library, which is used in gpc, but that there is also a cephes library for this case. I have made no check to compare them.
So it is certainly wise to switch to gpc.
Hope this helps
Maurice