[comp.lang.modula2] FST bug

Pat.Terry@p101.f4.n494.z5.fidonet.org (Pat Terry) (11/06/90)

There is a slight bug in the FST 2.0 RealConversions module.

It does not round negative values correctly.  Better code would be as follows

For the LONGREAL bit

    PROCEDURE putRealF( x :REAL; nd, n :INTEGER );
    VAR neg :BOOLEAN;
        d   :ARRAY [0..MaxMantDigs] OF CHAR;
        i   :INTEGER;
        decAt, int :INTEGER;
    BEGIN
        IF n < nd+2 THEN ok := FALSE; RETURN END;
        n := n - (nd+2);
*        IF x >= 0.0
*          THEN x := x + SHORT(5.0/TenTo(nd+1));       (* round *)
*          ELSE x := x - SHORT(5.0/TenTo(nd+1));       (* round *)
        END;

and for the REAL bit

*        IF x >= 0.0
*          THEN x := x + 5.0/TenTo(nd+1);       (* round *)
*          ELSE x := x - 5.0/TenTo(nd+1);       (* round *)
*        END;



--  
uucp: uunet!m2xenix!puddle!5!494!4.101!Pat.Terry
Internet: Pat.Terry@p101.f4.n494.z5.fidonet.org