diff --git a/lang/m2/libm2/RealConver.mod b/lang/m2/libm2/RealConver.mod index 2e29b9765..493dc914b 100644 --- a/lang/m2/libm2/RealConver.mod +++ b/lang/m2/libm2/RealConver.mod @@ -85,8 +85,8 @@ IMPLEMENTATION MODULE RealConversions; ind2 := ndigits+1; IF NOT ecvtflag THEN - IF INTEGER(ind2) + pointpos < 0 THEN - ind2 := 0; + IF INTEGER(ind2) + pointpos <= 0 THEN + ind2 := 1; ELSE ind2 := INTEGER(ind2) + pointpos END; @@ -119,6 +119,10 @@ IMPLEMENTATION MODULE RealConversions; END; END; END; + IF (NOT ecvtflag) AND (ind1 = 0) THEN + str[0] := CHR(ORD(str[0])-5); + INC(ind1); + END; END; IF ecvtflag THEN FOR i := ind1 TO 2 BY -1 DO @@ -169,8 +173,13 @@ IMPLEMENTATION MODULE RealConversions; END; IF ndigits = 0 THEN str[pointpos] := 0C; + ind1 := pointpos - 1; ELSE str[pointpos] := '.'; + IF INTEGER(ind1) > pointpos+INTEGER(ndigits) THEN + ind1 := pointpos+INTEGER(ndigits); + END; + str[pointpos+INTEGER(ndigits)+1] := 0C; END; IF sign THEN FOR i := ind1 TO 0 BY -1 DO diff --git a/lang/m2/libm2/random.mod b/lang/m2/libm2/random.mod index db8225626..487b47b14 100644 --- a/lang/m2/libm2/random.mod +++ b/lang/m2/libm2/random.mod @@ -12,15 +12,16 @@ IMPLEMENTATION MODULE random; *) FROM Unix IMPORT getpid, time; -TYPE index = [0..54]; +TYPE index = [1..55]; VAR X: ARRAY index OF CARDINAL; - k, j: index; + j, k: index; + tm: LONGINT; PROCEDURE Random(): CARDINAL; BEGIN - IF k+1 > 54 THEN k := 0; ELSE INC(k) END; - IF j+1 > 54 THEN j := 0; ELSE INC(j) END; + IF k-1 <= 0 THEN k := 55; ELSE DEC(k) END; + IF j-1 <= 0 THEN j := 55; ELSE DEC(j) END; X[k] := X[k] + X[j]; RETURN X[k] END Random; @@ -32,16 +33,26 @@ BEGIN END Uniform; PROCEDURE StartSeed(seed: CARDINAL); +VAR v: CARDINAL; BEGIN - X[0] := seed; - FOR k := 1 TO 54 DO - X[k] := X[k-1] * 1297; + FOR k := 1 TO 55 DO + seed := 1297 * seed + 123; + X[k] := seed; END; - k := 54; - j := 30; + FOR k := 1 TO 15 DO + j := tm MOD 55D + 1D; + v := X[j]; + tm := tm DIV 7D; + j := tm MOD 55D + 1D; + X[j] := v; + tm := tm * 3D; + END; + k := 1; + j := 25; END StartSeed; BEGIN - X[0] := time(NIL); - StartSeed(CARDINAL(getpid()) * X[0]); + tm := time(NIL); + X[1] := tm; + StartSeed(CARDINAL(getpid()) * X[1]); END random.