[comp.lang.modula2] Fixed Point Output with WriteReal

CCECKS@NUSVM.BITNET (Chua KS) (08/06/89)

   Hi. I'm a neophyte in Modula-2 and I have a very simple question to
ask.  Is it possible to get fixed point rather than floating point
output using WriteReal (a la FORTRAN F6.3 for eg).  The book that
I'm using now does not mention anything about fixed point output, so
maybe I'm missing something.  Would appreciate a reply.  Thanks.

Chua KS.

lins@APPLE.COM (Chuck Lins) (08/07/89)

In article <INFO-M2%89080522371415@UCF1VM> you write:
>
>   Hi. I'm a neophyte in Modula-2 and I have a very simple question to
>ask.  Is it possible to get fixed point rather than floating point
>output using WriteReal (a la FORTRAN F6.3 for eg).  The book that
>I'm using now does not mention anything about fixed point output, so
>maybe I'm missing something.  Would appreciate a reply.  Thanks.
>
>Chua KS.

This is one of the flaws of the RealInOut module - it lacks a parameter
specifying the precision or whether to use fixed or floating point output.
Of course, it's always possible to write your own routine to do this but you
shouldn't have to. If your compiler system doesn't include such a feature
complain to the vendor. If enough people complain they might actually add the
feature.

A cheap workaround exists if your compiler supports declaration of EXTERNAL
routines which are coded in another language AND you have a routine written in
another language that does what you want. You can declare the routine as
EXTERNAL and then make calls to it as though it was written in Modula-2.


--
Chuck Lins                      | "Exit right to funway."
Internet:   lins@apple.com      | AppleLink: LINS
Snail Mail: 20525 Mariani Ave. M/S: 41-K Cupertino, CA 95014

stenake@KULING.DOCS.UU.SE ("Mr Sten-]ke Lindell") (08/15/89)

In article <INFO-M2%89080522371415@UCF1VM> you write:
>
>   Hi. I'm a neophyte in Modula-2 and I have a very simple question to
>ask.  Is it possible to get fixed point rather than floating point
>output using WriteReal (a la FORTRAN F6.3 for eg).  The book that
>I'm using now does not mention anything about fixed point output, so
>maybe I'm missing something.  Would appreciate a reply.  Thanks.
>
>Chua KS.

MODULE Gazonk;

FROM InOut IMPORT
   WriteLn, WriteString;

FROM RealConversions IMPORT
   RealToString;

PROCEDURE WriteFix (R : REAL; Dec, Width : CARDINAL);
VAR
   tmpstr : ARRAY [0..80] OF CHAR;
   ok     : BOOLEAN;

BEGIN
   RealToString (R, INTEGER (Dec), INTEGER (Width), tmpstr, ok);
   WriteString (tmpstr)
END WriteFix;

BEGIN
   WriteFix (42.666, 3, 6);
   WriteLn;
END Gazonk.