On Apr 14, 3:31 am, glen herrmannsfeldt <
g...@ugcs.caltech.edu> wrote:
> Mike Zimnov <
mikez...@gmail.com> wrote:
> > I try to transtalte to pl/i some Fortran module and have few questions:
> > 1. Are PL/I PACKAGE similar to Fortran MODULE? What are differences?
> > 2. As I see PL/I have no analog to SELECTED_REAL_KIND builtin. Is possible to translate
> > INTEGER, PARAMETER :: kp = kind(1.) ! For single precision
> > INTEGER, PARAMETER :: kp = kind(1D0) ! For double precision and the default
> > INTEGER,PARAMETER :: kp=SELECTED_REAL_KIND(20,550) ! For extended precision
>
> I suppose you could use the preprocessor in place of PARAMETER.
>
> %DCL KP FIXED;
> %KP=16;
That is largely irrelevant.
The exactly corresponding PL/I facility is to specify the number
of digits required, e.g.,
declare x float(10);
which selects an appropriate storage unit capable of storing
at least 10 decimal digits.
> Good or bad, PL/I does such typing at a higher level. You specify
> the precision that you want, and the compiler gives you an appropriate
> type.
It gives a storage unit capable of storing at least the
number of digits required, in whatever mode corresponding
to the declaration (decimal, bonary, fixed, float).
It's exactly the same as what's available with Fortran's
KIND type facility (examples of which are given above).
> At the time PL/I was being designed, there was nothing close
> to a standard floating point format.
More to the point, there was nothing consistent about word sizes,
and some machines were character- (byte)-oriented while others were
word-oriented.
> Even more, single precision on
> some machines was close to double precision on others.
In terms of floating-point, yes. Those terms weren't relevant to
binary integer or decimal integer, or scaled fixed-point.
> > and then use construtions like
> > REAL (kp), PARAMETER :: pi = 3.14159265358979323846264_kp
> > in PL/I?
>
> I don't know if PL/I now has something closer to Fortran PARAMETER.
I gave an example the day prior to your post.
You use the VALUE attribute in PL/I, which is exactly the same
as Fortran's PARAMETER.
> Constants have the base, mode, scale, and precision that they are
> written in. You pi is FIXED DECIMAL(24,23). If you want a floating
> point constant, add an E0 at the end, which would make it
> FLOAT DECIMAL(24).
>
> Note that PL/I has no feature like Fortran where constants have less
> precision than written.
Thank goodness! And it's not a Fortran "feature". It's archaic.
> In Fortran 3.14159265358979323846264 is single
> precision, in PL/I it is more than double (on most machines).
>
> If you want to specify the precision of a constant, I think you can
> do something like FLOAT(3.14159265358979323846264,16) to specify
> that you want 16 (decimal) digits. (The compiler will round up
> to the next available floating point form.)
>
> Fortran only allows you to specify precision in decimal digits.
> PL/I allows you to specify in either binary bits or decimal
> digits. Until very recently, there were no machines supporting
> both binary and decimal floating point. Like Fortran, FIXED DEC
> specified the required precision,
Fortran does NOT have fixed decimal.
> but did not specify that
> you actually wanted decimal floating point. I don't know that
> any actual compilers have been upgraded to support decimal
> floating point, but it should happen.
IBM's PL/I supports decimal and binary floating-point.
Has done so for at least 3½ years, maybe more.
> Otherwise, you can specify FLOAT BINARY(53) or something similar.
> Or even:
>
> %DCL KP FIXED;
> %KP=16;
> DCL X FIXED BINARY(KP*332/100);
Why on earth would you want to do that!
>
> or maybe
>
> %DCL (KP,KPB) FIXED;
> %KP=16;
> %KPB=KP*332/100;
> DCL X FIXED BINARY(KPB);
You have to be joking.